forked from qt-creator/qt-creator
FakeVim: Keep undo/redo integrity while the plugin is disabled
Change-Id: If17252ecfd7adc6bbe518ce97908f1f8fb2772f1 Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -1794,6 +1794,7 @@ public:
|
|||||||
QStack<State> m_undo;
|
QStack<State> m_undo;
|
||||||
QStack<State> m_redo;
|
QStack<State> m_redo;
|
||||||
State m_undoState;
|
State m_undoState;
|
||||||
|
int m_lastUndoSteps;
|
||||||
|
|
||||||
// extra data for '.'
|
// extra data for '.'
|
||||||
void replay(const QString &text);
|
void replay(const QString &text);
|
||||||
@@ -1957,6 +1958,7 @@ FakeVimHandler::Private::Private(FakeVimHandler *parent, QWidget *widget)
|
|||||||
if (editor()) {
|
if (editor()) {
|
||||||
connect(EDITOR(document()), SIGNAL(contentsChanged()), SLOT(onContentsChanged()));
|
connect(EDITOR(document()), SIGNAL(contentsChanged()), SLOT(onContentsChanged()));
|
||||||
connect(EDITOR(document()), SIGNAL(undoCommandAdded()), SLOT(onUndoCommandAdded()));
|
connect(EDITOR(document()), SIGNAL(undoCommandAdded()), SLOT(onUndoCommandAdded()));
|
||||||
|
m_lastUndoSteps = document()->availableUndoSteps();
|
||||||
}
|
}
|
||||||
//new Highlighter(document(), &pythonRules);
|
//new Highlighter(document(), &pythonRules);
|
||||||
init();
|
init();
|
||||||
@@ -2375,10 +2377,7 @@ void FakeVimHandler::Private::restoreWidget(int tabSize)
|
|||||||
EDITOR(setTabStopWidth(charWidth * tabSize));
|
EDITOR(setTabStopWidth(charWidth * tabSize));
|
||||||
m_visualMode = NoVisualMode;
|
m_visualMode = NoVisualMode;
|
||||||
// Force "ordinary" cursor.
|
// Force "ordinary" cursor.
|
||||||
m_mode = InsertMode;
|
EDITOR(setOverwriteMode(false));
|
||||||
m_submode = NoSubMode;
|
|
||||||
m_subsubmode = NoSubSubMode;
|
|
||||||
updateCursorShape();
|
|
||||||
updateSelection();
|
updateSelection();
|
||||||
updateHighlights();
|
updateHighlights();
|
||||||
}
|
}
|
||||||
@@ -7090,17 +7089,37 @@ void FakeVimHandler::Private::onContentsChanged()
|
|||||||
{
|
{
|
||||||
if (!document()->isUndoAvailable())
|
if (!document()->isUndoAvailable())
|
||||||
m_undo.clear();
|
m_undo.clear();
|
||||||
else if (m_editBlockLevel == 0 && !m_undo.isEmpty() && !isInsertMode())
|
|
||||||
m_undo.push(State()); // Save undo state for external change.
|
const int undoSteps = document()->availableUndoSteps();
|
||||||
|
|
||||||
|
if (m_editBlockLevel == 0) {
|
||||||
|
// Break undo/redo stacks on external undo/redo.
|
||||||
|
if (m_lastUndoSteps > undoSteps && !m_undo.isEmpty()) {
|
||||||
|
if ((--m_undo.top().revisions) <= 0)
|
||||||
|
m_undo.pop();
|
||||||
|
m_redo.push(State());
|
||||||
|
} else if (m_lastUndoSteps < undoSteps && !m_redo.isEmpty()) {
|
||||||
|
if ((--m_redo.top().revisions) <= 0)
|
||||||
|
m_redo.pop();
|
||||||
|
m_undo.push(State());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_lastUndoSteps = undoSteps;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimHandler::Private::onUndoCommandAdded()
|
void FakeVimHandler::Private::onUndoCommandAdded()
|
||||||
{
|
{
|
||||||
m_redo.clear();
|
m_redo.clear();
|
||||||
if (m_editBlockLevel == 0 && !m_undo.isEmpty() && isInsertMode())
|
// Remember chage so it can be correctly undone/redone with undo/redo commands.
|
||||||
++m_undo.top().revisions;
|
if (m_editBlockLevel == 0 && !m_undo.isEmpty()) {
|
||||||
|
if (isInsertMode())
|
||||||
|
++m_undo.top().revisions; // External change in insert mode (auto-completion etc.)
|
||||||
else
|
else
|
||||||
++m_undoState.revisions;
|
m_undo.push(State()); // External change while FakeVim disabled.
|
||||||
|
} else if (m_editBlockLevel > 0) {
|
||||||
|
++m_undoState.revisions; // Document revision increased in our edit block.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char FakeVimHandler::Private::currentModeCode() const
|
char FakeVimHandler::Private::currentModeCode() const
|
||||||
@@ -7164,11 +7183,11 @@ void FakeVimHandler::Private::undoRedo(bool undo)
|
|||||||
setMark(QLatin1Char('`'), lastPos);
|
setMark(QLatin1Char('`'), lastPos);
|
||||||
setCursorPosition(m_lastChangePosition);
|
setCursorPosition(m_lastChangePosition);
|
||||||
setAnchor();
|
setAnchor();
|
||||||
stack2.push(state);
|
|
||||||
} else {
|
} else {
|
||||||
updateFirstVisibleLine();
|
updateFirstVisibleLine();
|
||||||
m_cursor = EDITOR(textCursor());
|
m_cursor = EDITOR(textCursor());
|
||||||
}
|
}
|
||||||
|
stack2.push(state);
|
||||||
|
|
||||||
setTargetColumn();
|
setTargetColumn();
|
||||||
if (atEndOfLine())
|
if (atEndOfLine())
|
||||||
|
Reference in New Issue
Block a user