diff --git a/src/plugins/fakevim/fakevim_test.cpp b/src/plugins/fakevim/fakevim_test.cpp index 37749b3375e..02857af2cf1 100644 --- a/src/plugins/fakevim/fakevim_test.cpp +++ b/src/plugins/fakevim/fakevim_test.cpp @@ -2384,11 +2384,11 @@ void FakeVimPlugin::test_vim_command_J() KEYS("J", lmid(0, 5) + "| " + lmid(5)); KEYS("u", lmid(0, 4) + "\nint |main(int argc, char *argv[])\n" + lmid(5)); - COMMAND("redo", lmid(0, 5) + "| " + lmid(5)); + COMMAND("redo", lmid(0, 4) + "\nint |main(int argc, char *argv[]) " + lmid(5)); KEYS("3J", lmid(0, 5) + " " + lmid(5, 1) + " " + lmid(6, 1).mid(4) + "| " + lmid(7)); KEYS("uu", lmid(0, 4) + "\nint |main(int argc, char *argv[])\n" + lmid(5)); - COMMAND("redo", lmid(0, 5) + "| " + lmid(5)); + COMMAND("redo", lmid(0, 4) + "\nint |main(int argc, char *argv[]) " + lmid(5)); } void FakeVimPlugin::test_vim_command_put_at_eol() diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index 810893a01fa..74e4f9cd8e9 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -3461,13 +3461,12 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input) } else if (input.isControl('i')) { jump(count()); } else if (input.is('J')) { + setUndoPosition(); moveBehindEndOfLine(); - const int pos = position(); beginEditBlock(); if (m_submode == NoSubMode) joinLines(count(), m_gflag); endEditBlock(); - setPosition(pos); setDotCommand("%1J", count()); } else if (input.isControl('l')) { // screen redraw. should not be needed @@ -6204,8 +6203,11 @@ void FakeVimHandler::Private::pasteText(bool afterCursor) void FakeVimHandler::Private::joinLines(int count, bool preserveSpace) { - for (int i = qMax(count - 2, 0); i >= 0; --i) { + int pos = position(); + const int blockNumber = cursor().blockNumber(); + for (int i = qMax(count - 2, 0); i >= 0 && blockNumber < document()->blockCount(); --i) { moveBehindEndOfLine(); + pos = position(); setAnchor(); moveRight(); if (preserveSpace) { @@ -6216,6 +6218,7 @@ void FakeVimHandler::Private::joinLines(int count, bool preserveSpace) cursor().insertText(QString(QLatin1Char(' '))); } } + setPosition(pos); } QString FakeVimHandler::Private::lineContents(int line) const