diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index ce04adfa6a9..e18599d7072 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -620,8 +620,9 @@ void FakeVimHandler::Private::moveDown(int n) m_tc.movePosition(Down, MoveAnchor, n); #else const int col = m_tc.position() - m_tc.block().position(); - const int line = m_tc.block().blockNumber(); - const QTextBlock &block = m_tc.document()->findBlockByNumber(line + n); + const int lastLine = m_tc.document()->lastBlock().blockNumber(); + const int targetLine = qMax(0, qMin(lastLine, m_tc.block().blockNumber() + n)); + const QTextBlock &block = m_tc.document()->findBlockByNumber(targetLine); const int pos = block.position(); setPosition(pos + qMin(block.length() - 1, col)); moveToTargetColumn(); diff --git a/tests/auto/fakevim/main.cpp b/tests/auto/fakevim/main.cpp index df4b6d691a2..fd5b06f0931 100644 --- a/tests/auto/fakevim/main.cpp +++ b/tests/auto/fakevim/main.cpp @@ -302,6 +302,7 @@ void tst_FakeVim::command_e() move("e", "int main(int argc, char *arg@v[])"); move("e", "int main(int argc, char *argv[]@)"); move("e", "@{"); + move("10k","@\n"); // home. } void tst_FakeVim::command_i()