From 523baa4fdcbb27d3f475018505d9352d8f79645e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 19 Jan 2014 21:28:10 +0100 Subject: [PATCH] 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. --- src/apps/haiku-depot/textview/TextEditor.cpp | 24 +++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/apps/haiku-depot/textview/TextEditor.cpp b/src/apps/haiku-depot/textview/TextEditor.cpp index 2c803e9d00..62b46ea80c 100644 --- a/src/apps/haiku-depot/textview/TextEditor.cpp +++ b/src/apps/haiku-depot/textview/TextEditor.cpp @@ -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; }