diff --git a/src/plugins/fakevim/fakevim_test.cpp b/src/plugins/fakevim/fakevim_test.cpp index 1881379ecff..75878432464 100644 --- a/src/plugins/fakevim/fakevim_test.cpp +++ b/src/plugins/fakevim/fakevim_test.cpp @@ -1370,6 +1370,60 @@ void FakeVimPlugin::test_vim_jumps() KEYS("", "abc" N "def" N "g" X "hi"); } +void FakeVimPlugin::test_vim_current_column() +{ + // Check if column is correct after command and vertical cursor movement. + TestData data; + setup(&data); + + // always at end of line after + data.setText(" abc" N " def 123" N "" N " ghi"); + KEYS("", " abc" N " def 12" X "3" N "" N " ghi"); + KEYS("", " abc" N " def 123" N "" N " gh" X "i"); + KEYS("", " abc" N " def 123" N X "" N " ghi"); + KEYS("", " abc" N " def 12" X "3" N "" N " ghi"); + // ... in insert + KEYS("i", " abc" X N " def 123" N "" N " ghi"); + KEYS("i", " abc" N " def 123" X N "" N " ghi"); + + // vertical movement doesn't reset column + data.setText(" abc" N " def 1" X "23" N "" N " ghi"); + KEYS("", " ab" X "c" N " def 123" N "" N " ghi"); + KEYS("", " abc" N " def 1" X "23" N "" N " ghi"); + KEYS("", " abc" N " def 123" N "" N " gh" X "i"); + KEYS("", " abc" N " def 1" X "23" N "" N " ghi"); + KEYS("^jj", " abc" N " def 123" N "" N " " X "ghi"); + KEYS("kk", " abc" N " " X "def 123" N "" N " ghi"); + + // yiw, yaw + data.setText(" abc" N " def" N " ghi"); + KEYS("e", " abc" N " de" X "f" N " ghi"); + KEYS("b", " abc" N " def" N " " X "ghi"); + KEYS("ll", " abc" N " de" X "f" N " ghi"); + KEYS("yiw", " abc" N " " X "def" N " ghi"); + KEYS("llyaw", " " X "abc" N " def" N " ghi"); + + // insert + data.setText(" abc" N " def" N " ghi"); + KEYS("lljj", " abc" N " def" N " " X "ghi"); + KEYS("i123", " abc" N " def" X N " 123ghi"); + KEYS("a456", " abc" N " def456" X N " 123ghi"); + + data.setText(" abc" N X " def 123" N "" N " ghi"); + KEYS("A", " abc" N " def 123" N "" N " ghi" X); + KEYS("A", " abc" N " def" X " 123" N "" N " ghi"); + KEYS("A", " abc" N " def 123" X N "" N " ghi"); + + data.setText(" abc" N X " def 123" N "" N " ghi"); + KEYS("I", " abc" N " def 123" N "" N " " X "ghi"); + + // change + data.setText(" abc" N " d" X "ef" N " ghi"); + KEYS("cc", " " X "abc" N " " N " ghi"); + data.setText(" abc" N " d" X "ef" N " ghi"); + KEYS("ccx", " xabc" N " " N " g" X "hi"); +} + void FakeVimPlugin::test_vim_copy_paste() { TestData data; diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index b3cc113ed3d..43927ef4273 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -2137,7 +2137,10 @@ void FakeVimHandler::Private::recordInsertion(const QString &insert) m_lastInsertion += insert; } - m_oldPosition = position(); + if (m_oldPosition != pos) { + m_oldPosition = pos; + setTargetColumn(); + } } void FakeVimHandler::Private::ensureCursorVisible() @@ -2707,11 +2710,10 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommandMovement) if (m_rangemode == RangeLineMode) { if (isVisualMode()) moveToStartOfLine(); - else - setTargetColumn(); } } leaveVisualMode(); + setTargetColumn(); } else if (m_submode == InvertCaseSubMode || m_submode == UpCaseSubMode || m_submode == DownCaseSubMode) { @@ -3451,6 +3453,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input) setUndoPosition(); setAnchor(); enterInsertMode(); + setTargetColumn(); setDotCommand(_("%1A"), count()); } else if (input.isControl('a')) { if (changeNumberTextObject(count())) @@ -3561,6 +3564,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input) setUndoPosition(); breakEditBlock(); enterInsertMode(); + setTargetColumn(); } else if (input.isControl('i')) { jump(count()); } else if (input.is('J')) { @@ -4029,9 +4033,11 @@ EventResult FakeVimHandler::Private::handleReplaceMode(const Input &input) } else if (input.isKey(Key_Left)) { breakEditBlock(); moveLeft(1); + setTargetColumn(); } else if (input.isKey(Key_Right)) { breakEditBlock(); moveRight(1); + setTargetColumn(); } else if (input.isKey(Key_Up)) { breakEditBlock(); moveUp(1); @@ -4059,7 +4065,6 @@ EventResult FakeVimHandler::Private::handleReplaceMode(const Input &input) recordInsertion(); } m_oldPosition = position(); - setTargetColumn(); updateMiniBuffer(); return EventHandled; @@ -4145,9 +4150,11 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input) } else if (input.isKey(Key_Left)) { moveLeft(count()); move = true; + setTargetColumn(); } else if (input.isControl(Key_Left)) { moveToNextWordStart(count(), false, false); move = true; + setTargetColumn(); } else if (input.isKey(Key_Down)) { //removeAutomaticIndentation(); m_submode = NoSubMode; @@ -4161,18 +4168,22 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input) } else if (input.isKey(Key_Right)) { moveRight(count()); move = true; + setTargetColumn(); } else if (input.isControl(Key_Right)) { moveToNextWordStart(count(), false, true); moveRight(); // we need one more move since we are in insert mode move = true; + setTargetColumn(); } else if (input.isKey(Key_Home)) { moveToStartOfLine(); move = true; + setTargetColumn(); } else if (input.isKey(Key_End)) { if (count() > 1) moveDown(count() - 1); moveBehindEndOfLine(); move = true; + setTargetColumn(); } else if (input.isReturn() || input.isControl('j') || input.isControl('m')) { joinPreviousEditBlock(); m_submode = NoSubMode; @@ -4277,7 +4288,6 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input) m_lastInsertion.clear(); recordInsertion(insert); } - setTargetColumn(); updateMiniBuffer(); return EventHandled; diff --git a/src/plugins/fakevim/fakevimplugin.h b/src/plugins/fakevim/fakevimplugin.h index 58594727f84..87a558723b0 100644 --- a/src/plugins/fakevim/fakevimplugin.h +++ b/src/plugins/fakevim/fakevimplugin.h @@ -75,6 +75,7 @@ private slots: void test_vim_indent(); void test_vim_marks(); void test_vim_jumps(); + void test_vim_current_column(); void test_vim_copy_paste(); void test_vim_undo_redo(); void test_vim_letter_case();