forked from qt-creator/qt-creator
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:
@@ -1440,8 +1440,11 @@ public:
|
|||||||
void init();
|
void init();
|
||||||
void focus();
|
void focus();
|
||||||
|
|
||||||
void enterFakeVim(); // Call before any FakeVim processing (import cursor position from editor)
|
// Call before any FakeVim processing (import cursor position from editor)
|
||||||
void leaveFakeVim(); // Call after any FakeVim processing (export cursor position to 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 handleKey(const Input &input);
|
||||||
EventResult handleDefaultKey(const Input &input);
|
EventResult handleDefaultKey(const Input &input);
|
||||||
@@ -2049,7 +2052,7 @@ void FakeVimHandler::Private::enterFakeVim()
|
|||||||
moveRight();
|
moveRight();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimHandler::Private::leaveFakeVim()
|
void FakeVimHandler::Private::leaveFakeVim(bool needUpdate)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_inFakeVim, qDebug() << "enterFakeVim() not called before leaveFakeVim()!");
|
QTC_ASSERT(m_inFakeVim, qDebug() << "enterFakeVim() not called before leaveFakeVim()!");
|
||||||
|
|
||||||
@@ -2071,15 +2074,18 @@ void FakeVimHandler::Private::leaveFakeVim()
|
|||||||
|
|
||||||
exportSelection();
|
exportSelection();
|
||||||
updateCursorShape();
|
updateCursorShape();
|
||||||
commitCursor();
|
|
||||||
|
|
||||||
// Move cursor line to middle of screen if it's not visible.
|
if (needUpdate) {
|
||||||
const int line = cursorLine();
|
commitCursor();
|
||||||
if (line < firstVisibleLine() || line >= firstVisibleLine() + linesOnScreen())
|
|
||||||
scrollToLine(qMax(0, line - linesOnScreen() / 2));
|
// Move cursor line to middle of screen if it's not visible.
|
||||||
else
|
const int line = cursorLine();
|
||||||
scrollToLine(firstVisibleLine());
|
if (line < firstVisibleLine() || line >= firstVisibleLine() + linesOnScreen())
|
||||||
updateScrollOffset();
|
scrollToLine(qMax(0, line - linesOnScreen() / 2));
|
||||||
|
else
|
||||||
|
scrollToLine(firstVisibleLine());
|
||||||
|
updateScrollOffset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_inFakeVim = false;
|
m_inFakeVim = false;
|
||||||
@@ -2183,7 +2189,7 @@ EventResult FakeVimHandler::Private::handleEvent(QKeyEvent *ev)
|
|||||||
|
|
||||||
enterFakeVim();
|
enterFakeVim();
|
||||||
EventResult result = handleKey(Input(key, mods, ev->text()));
|
EventResult result = handleKey(Input(key, mods, ev->text()));
|
||||||
leaveFakeVim();
|
leaveFakeVim(result == EventHandled);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -2592,8 +2598,8 @@ void FakeVimHandler::Private::timerEvent(QTimerEvent *ev)
|
|||||||
{
|
{
|
||||||
if (ev->timerId() == g.inputTimer) {
|
if (ev->timerId() == g.inputTimer) {
|
||||||
enterFakeVim();
|
enterFakeVim();
|
||||||
handleKey(Input());
|
EventResult result = handleKey(Input());
|
||||||
leaveFakeVim();
|
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
|
// 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
|
// - otherwise the text would be inserted while being in command mode
|
||||||
if (input.text().isEmpty())
|
if (input.text().isEmpty())
|
||||||
handled = EventUnhandled;
|
handled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateMiniBuffer();
|
updateMiniBuffer();
|
||||||
@@ -6329,6 +6335,11 @@ void FakeVimHandler::Private::scrollToLine(int line)
|
|||||||
{
|
{
|
||||||
const QTextCursor tc = EDITOR(textCursor());
|
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;
|
QTextCursor tc2 = tc;
|
||||||
tc2.setPosition(document()->lastBlock().position());
|
tc2.setPosition(document()->lastBlock().position());
|
||||||
EDITOR(setTextCursor(tc2));
|
EDITOR(setTextCursor(tc2));
|
||||||
|
Reference in New Issue
Block a user