From 5a8501ffafd24725106b687c8c658354bb370f26 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 21 Oct 2020 17:45:48 +0200 Subject: [PATCH] CppEditor: Fix over-eager undo We must not call QTextDocument::joinPreviousEditBlock() unless the symbol name was actually edited, i.e. key presses that don't change the content do not count. Otherwise, QTextDocument will merge the renaming action with the previous change to the document in its undo stack. Fixes: QTCREATORBUG-16350 Change-Id: Ie5a3a6a2f5a15caa038bf111673d4c32077fe4ba Reviewed-by: David Schulz --- src/plugins/cppeditor/cpplocalrenaming.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/plugins/cppeditor/cpplocalrenaming.cpp b/src/plugins/cppeditor/cpplocalrenaming.cpp index 14a7a93fc2b..5713a02fdda 100644 --- a/src/plugins/cppeditor/cpplocalrenaming.cpp +++ b/src/plugins/cppeditor/cpplocalrenaming.cpp @@ -193,16 +193,22 @@ bool CppLocalRenaming::handleKeyPressEvent(QKeyEvent *e) startRenameChange(); const bool wantEditBlock = isWithinRenameSelection(cursorPosition); + const int undoSizeBeforeEdit = m_editorWidget->document()->availableUndoSteps(); if (wantEditBlock) { if (m_firstRenameChangeExpected) // Change inside rename selection cursor.beginEditBlock(); else cursor.joinPreviousEditBlock(); - m_firstRenameChangeExpected = false; } emit processKeyPressNormally(e); - if (wantEditBlock) + if (wantEditBlock) { cursor.endEditBlock(); + if (m_firstRenameChangeExpected + // QTCREATORBUG-16350 + && m_editorWidget->document()->availableUndoSteps() != undoSizeBeforeEdit) { + m_firstRenameChangeExpected = false; + } + } finishRenameChange(); return true; }