TextEditor: Control caret offset in Insert/Remove()...

... and fix the invalidation to happen after the operation, since it currently
updates the layout text spans synchronously.
This commit is contained in:
Stephan Aßmus
2014-01-20 00:50:33 +01:00
parent 25dcdbc2b5
commit 523baa4fdc
+18 -6
View File
@@ -243,10 +243,16 @@ TextEditor::Insert(int32 offset, const BString& string)
if (!fEditingEnabled || fDocument.Get() == NULL)
return B_ERROR;
// TODO: Via listener, and only affected paragraphs
fLayout->Invalidate();
status_t ret = fDocument->Insert(offset, string, fStyleAtCaret);
return fDocument->Insert(offset, string, fStyleAtCaret);
if (ret == B_OK) {
// TODO: Via listener, and only affected paragraphs
fLayout->Invalidate();
_SetCaretOffset(offset + string.CountChars(), true, false, true);
}
return ret;
}
@@ -256,10 +262,16 @@ TextEditor::Remove(int32 offset, int32 length)
if (!fEditingEnabled || fDocument.Get() == NULL)
return B_ERROR;
// TODO: Via listener, and only affected paragraphs
fLayout->Invalidate();
status_t ret = fDocument->Remove(offset, length);
return fDocument->Remove(offset, length);
if (ret == B_OK) {
// TODO: Via listener, and only affected paragraphs
fLayout->Invalidate();
_SetCaretOffset(offset, true, false, true);
}
return ret;
}