forked from qt-creator/qt-creator
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 <david.schulz@qt.io>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user