From d8a56f9dc1887b9eff2fbe8bd86a784860df456f Mon Sep 17 00:00:00 2001 From: hluk Date: Wed, 19 Feb 2014 19:18:14 +0100 Subject: [PATCH] FakeVim: Save and restore cursor if handling custom Ex command Change-Id: I38ee04fd76f92b0e0e5755e6a9f8828bd347c245 Reviewed-by: hjk --- src/plugins/fakevim/fakevimhandler.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index e61b66e572e..7f1fc081adf 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -1780,6 +1780,11 @@ public: if (editor()) EDITOR(setTextCursor(m_cursor)); } + // Restore cursor from editor widget. + void pullCursor() { + if (editor()) + m_cursor = EDITOR(textCursor()); + } // Values to save when starting FakeVim processing. int m_firstVisibleLine; @@ -2235,7 +2240,7 @@ void FakeVimHandler::Private::enterFakeVim() { QTC_ASSERT(!m_inFakeVim, qDebug() << "enterFakeVim() shouldn't be called recursively!"; return); - m_cursor = EDITOR(textCursor()); + pullCursor(); if (m_cursor.isNull()) m_cursor = QTextCursor(document()); @@ -6093,8 +6098,15 @@ bool FakeVimHandler::Private::handleExCommandHelper(ExCommand &cmd) bool FakeVimHandler::Private::handleExPluginCommand(const ExCommand &cmd) { bool handled = false; + int pos = m_cursor.position(); + commitCursor(); emit q->handleExCommandRequested(&handled, cmd); //qDebug() << "HANDLER REQUEST: " << cmd.cmd << handled; + if (handled) { + pullCursor(); + if (m_cursor.position() != pos) + recordJump(pos); + } return handled; } @@ -7276,7 +7288,7 @@ bool FakeVimHandler::Private::passEventToEditor(QEvent &event) updateCursorShape(); if (accepted) - m_cursor = EDITOR(textCursor()); + pullCursor(); return accepted; } @@ -7659,7 +7671,7 @@ void FakeVimHandler::Private::undoRedo(bool undo) state.revision = previousRevision; } else { updateFirstVisibleLine(); - m_cursor = EDITOR(textCursor()); + pullCursor(); } stack2.push(state);