diff --git a/src/plugins/fakevim/fakevim_test.cpp b/src/plugins/fakevim/fakevim_test.cpp index 05f64770c33..060fbb04f0d 100644 --- a/src/plugins/fakevim/fakevim_test.cpp +++ b/src/plugins/fakevim/fakevim_test.cpp @@ -798,6 +798,26 @@ void FakeVimPlugin::test_vim_delete_a_word() // delete single-character-word data.setText("a," X "b,c"); KEYS("daw", "a," X ",c"); + + // delete a word with visual selection + data.setText(X "a" N "" N "b"); + KEYS("vawd", X "" N "" N "b"); + data.setText(X "a" N "" N "b"); + KEYS("Vawd", X "" N "" N "b"); + + data.setText("abc def g" X "hi"); + KEYS("vawd", "abc de" X "f"); + KEYS("u", "abc def" X " ghi"); + + // backward visual selection + data.setText("abc def g" X "hi"); + KEYS("vhawd", "abc " X "i"); + + data.setText("abc def gh" X "i"); + KEYS("vhawd", "abc de" X "f"); + + data.setText("abc def gh" X "i"); + KEYS("vh2awd", "ab" X "c"); } void FakeVimPlugin::test_vim_change_a_word() diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index 832bfcfdb3f..cb111ff2db0 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -6795,7 +6795,10 @@ QString FakeVimHandler::Private::visualDotCommand() const void FakeVimHandler::Private::selectTextObject(bool simple, bool inner) { - bool setupAnchor = (position() == anchor()); + const int position1 = this->position(); + const int anchor1 = this->anchor(); + bool setupAnchor = (position1 == anchor1); + bool forward = anchor1 <= position1; const int repeat = count(); // set anchor if not already set @@ -6807,28 +6810,43 @@ void FakeVimHandler::Private::selectTextObject(bool simple, bool inner) } moveToBoundaryStart(1, simple, false); setAnchor(); - } else { + } else if (forward) { moveRight(); if (atEndOfLine()) moveRight(); + } else { + moveLeft(); + if (atBlockStart()) + moveLeft(); } if (inner) { moveToBoundaryEnd(repeat, simple); } else { + const int direction = forward ? 1 : -1; for (int i = 0; i < repeat; ++i) { // select leading spaces bool leadingSpace = characterAtCursor().isSpace(); - if (leadingSpace) - moveToNextBoundaryStart(1, simple); + if (leadingSpace) { + if (forward) + moveToNextBoundaryStart(1, simple); + else + moveToNextBoundaryEnd(1, simple, false); + } // select word - moveToWordEnd(1, simple); + if (forward) + moveToWordEnd(1, simple); + else + moveToWordStart(1, simple, false); // select trailing spaces if no leading space - if (!leadingSpace && document()->characterAt(position() + 1).isSpace() + if (!leadingSpace && document()->characterAt(position() + direction).isSpace() && !atBlockStart()) { - moveToNextBoundaryEnd(1, simple); + if (forward) + moveToNextBoundaryEnd(1, simple); + else + moveToNextBoundaryStart(1, simple, false); } // if there are no trailing spaces in selection select all leading spaces @@ -6842,9 +6860,15 @@ void FakeVimHandler::Private::selectTextObject(bool simple, bool inner) } if (i + 1 < repeat) { - moveRight(); - if (atEndOfLine()) + if (forward) { moveRight(); + if (atEndOfLine()) + moveRight(); + } else { + moveLeft(); + if (atBlockStart()) + moveLeft(); + } } } } @@ -6853,9 +6877,13 @@ void FakeVimHandler::Private::selectTextObject(bool simple, bool inner) m_movetype = MoveInclusive; } else { m_movetype = MoveExclusive; - moveRight(); - if (atEndOfLine()) + if (isNoVisualMode()) { moveRight(); + if (atEndOfLine()) + moveRight(); + } else if (isVisualLineMode()) { + m_visualMode = VisualCharMode; + } } setTargetColumn();