From 36ecf2c025a95b54f7cf53315b36dad4a6d86d0f Mon Sep 17 00:00:00 2001 From: Dan Cape Date: Fri, 21 Aug 2015 14:37:45 -0400 Subject: Fix QTextEdit/QQuickTextEdit undo bug - Part #2 If a user selected the text "foo" and typed "bar", upon pressing undo, the text would change to "b". This is incorrect and does not match the functionality of QLineEdit or the default behaviours of Windows/OSX/Ubuntu. This was fixed by a change made to always merge two sequential inserts if they are not part of the same block. Previously the selection delete and the "b" were part of one edit block and "ar" was part of another. With this change, the selection delete and "bar" are part of the same edit block. Unit test changes are part of a separate review (Part #1) since they required changes in qtdeclarative. [ChangeLog][QtGui][Important Behavior Changes] Fixed QTextEdit to match undo functionality of QLineEdit to group two sequential inserts into one undo action. Task-number: QTBUG-38825 Change-Id: I76bf30e331e3526277c3e0ade58cf95b611fc117 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qtextdocument_p.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/gui/text/qtextdocument_p.cpp') diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index 93071aaf59..df0d52d8e9 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -1077,8 +1077,9 @@ void QTextDocumentPrivate::appendUndoItem(const QTextUndoCommand &c) QTextUndoCommand &last = undoStack[undoState - 1]; if ( (last.block_part && c.block_part && !last.block_end) // part of the same block => can merge - || (!c.block_part && !last.block_part)) { // two single undo items => can merge - + || (!c.block_part && !last.block_part) // two single undo items => can merge + || (c.command == QTextUndoCommand::Inserted && last.command == c.command && (last.block_part && !c.block_part))) { + // two sequential inserts that are not part of the same block => can merge if (last.tryMerge(c)) return; } -- cgit v1.2.3