FakeVim: Scroll only if it's really necessary

Task-number:QTCREATORBUG-9483
Change-Id: I5836b38fd663aa5471bedd389aa786002791aa6e
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
hluk
2013-06-06 21:05:32 +02:00
committed by hjk
parent 17dcb6d38c
commit 79ae5a0f05

View File

@@ -1440,8 +1440,11 @@ public:
void init();
void focus();
void enterFakeVim(); // Call before any FakeVim processing (import cursor position from editor)
void leaveFakeVim(); // Call after any FakeVim processing (export cursor position to editor)
// Call before any FakeVim processing (import cursor position from editor)
void enterFakeVim();
// Call after any FakeVim processing
// (if needUpdate is true, export cursor position to editor and scroll)
void leaveFakeVim(bool needUpdate = true);
EventResult handleKey(const Input &input);
EventResult handleDefaultKey(const Input &input);
@@ -2049,7 +2052,7 @@ void FakeVimHandler::Private::enterFakeVim()
moveRight();
}
void FakeVimHandler::Private::leaveFakeVim()
void FakeVimHandler::Private::leaveFakeVim(bool needUpdate)
{
QTC_ASSERT(m_inFakeVim, qDebug() << "enterFakeVim() not called before leaveFakeVim()!");
@@ -2071,6 +2074,8 @@ void FakeVimHandler::Private::leaveFakeVim()
exportSelection();
updateCursorShape();
if (needUpdate) {
commitCursor();
// Move cursor line to middle of screen if it's not visible.
@@ -2081,6 +2086,7 @@ void FakeVimHandler::Private::leaveFakeVim()
scrollToLine(firstVisibleLine());
updateScrollOffset();
}
}
m_inFakeVim = false;
}
@@ -2183,7 +2189,7 @@ EventResult FakeVimHandler::Private::handleEvent(QKeyEvent *ev)
enterFakeVim();
EventResult result = handleKey(Input(key, mods, ev->text()));
leaveFakeVim();
leaveFakeVim(result == EventHandled);
return result;
}
@@ -2592,8 +2598,8 @@ void FakeVimHandler::Private::timerEvent(QTimerEvent *ev)
{
if (ev->timerId() == g.inputTimer) {
enterFakeVim();
handleKey(Input());
leaveFakeVim();
EventResult result = handleKey(Input());
leaveFakeVim(result == EventHandled);
}
}
@@ -3653,7 +3659,7 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
// if a key which produces text was pressed, don't mark it as unhandled
// - otherwise the text would be inserted while being in command mode
if (input.text().isEmpty())
handled = EventUnhandled;
handled = false;
}
updateMiniBuffer();
@@ -6329,6 +6335,11 @@ void FakeVimHandler::Private::scrollToLine(int line)
{
const QTextCursor tc = EDITOR(textCursor());
// Don't scroll if the line is already at the top.
updateFirstVisibleLine();
if (line == m_firstVisibleLine)
return;
QTextCursor tc2 = tc;
tc2.setPosition(document()->lastBlock().position());
EDITOR(setTextCursor(tc2));