Text framework: Added TextEditor::Replace()

Call Replace() on TextDocument, so that there are not two edits later
on once UndoableEdit stuff is supported.
This commit is contained in:
Stephan Aßmus 2015-09-06 23:09:36 +02:00
parent 41bd20b06b
commit 7d8d7785c1
2 changed files with 21 additions and 11 deletions

View File

@ -240,11 +240,7 @@ TextEditor::KeyDown(KeyEvent event)
// Handle null-termintating the string
BString text(event.bytes, event.length);
// Remove selection, if any
if (HasSelection())
Remove(SelectionStart(), SelectionLength());
Insert(fSelection.Caret(), text);
Replace(SelectionStart(), SelectionLength(), text);
}
break;
}
@ -260,9 +256,6 @@ TextEditor::Insert(int32 offset, const BString& string)
status_t ret = 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);
fDocument->PrintToStream();
@ -281,9 +274,6 @@ TextEditor::Remove(int32 offset, int32 length)
status_t ret = fDocument->Remove(offset, length);
if (ret == B_OK) {
// TODO: Via listener, and only affected paragraphs
fLayout->Invalidate();
_SetCaretOffset(offset, true, false, true);
fDocument->PrintToStream();
@ -293,6 +283,24 @@ TextEditor::Remove(int32 offset, int32 length)
}
status_t
TextEditor::Replace(int32 offset, int32 length, const BString& string)
{
if (!fEditingEnabled || fDocument.Get() == NULL)
return B_ERROR;
status_t ret = fDocument->Replace(offset, length, string);
if (ret == B_OK) {
_SetCaretOffset(offset + string.CountChars(), true, false, true);
fDocument->PrintToStream();
}
return ret;
}
// #pragma mark -

View File

@ -61,6 +61,8 @@ public:
virtual status_t Insert(int32 offset, const BString& string);
virtual status_t Remove(int32 offset, int32 length);
virtual status_t Replace(int32 offset, int32 length,
const BString& string);
void LineUp(bool select);
void LineDown(bool select);