forked from qt-creator/qt-creator
fakevim: Fix word selection in visual mode
Change-Id: I11a9831f2178f818639e04d7aad0eeb6c3f627fc Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -798,6 +798,26 @@ void FakeVimPlugin::test_vim_delete_a_word()
|
|||||||
// delete single-character-word
|
// delete single-character-word
|
||||||
data.setText("a," X "b,c");
|
data.setText("a," X "b,c");
|
||||||
KEYS("daw", "a," X ",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()
|
void FakeVimPlugin::test_vim_change_a_word()
|
||||||
|
|||||||
@@ -6795,7 +6795,10 @@ QString FakeVimHandler::Private::visualDotCommand() const
|
|||||||
|
|
||||||
void FakeVimHandler::Private::selectTextObject(bool simple, bool inner)
|
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();
|
const int repeat = count();
|
||||||
|
|
||||||
// set anchor if not already set
|
// set anchor if not already set
|
||||||
@@ -6807,28 +6810,43 @@ void FakeVimHandler::Private::selectTextObject(bool simple, bool inner)
|
|||||||
}
|
}
|
||||||
moveToBoundaryStart(1, simple, false);
|
moveToBoundaryStart(1, simple, false);
|
||||||
setAnchor();
|
setAnchor();
|
||||||
} else {
|
} else if (forward) {
|
||||||
moveRight();
|
moveRight();
|
||||||
if (atEndOfLine())
|
if (atEndOfLine())
|
||||||
moveRight();
|
moveRight();
|
||||||
|
} else {
|
||||||
|
moveLeft();
|
||||||
|
if (atBlockStart())
|
||||||
|
moveLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inner) {
|
if (inner) {
|
||||||
moveToBoundaryEnd(repeat, simple);
|
moveToBoundaryEnd(repeat, simple);
|
||||||
} else {
|
} else {
|
||||||
|
const int direction = forward ? 1 : -1;
|
||||||
for (int i = 0; i < repeat; ++i) {
|
for (int i = 0; i < repeat; ++i) {
|
||||||
// select leading spaces
|
// select leading spaces
|
||||||
bool leadingSpace = characterAtCursor().isSpace();
|
bool leadingSpace = characterAtCursor().isSpace();
|
||||||
if (leadingSpace)
|
if (leadingSpace) {
|
||||||
|
if (forward)
|
||||||
moveToNextBoundaryStart(1, simple);
|
moveToNextBoundaryStart(1, simple);
|
||||||
|
else
|
||||||
|
moveToNextBoundaryEnd(1, simple, false);
|
||||||
|
}
|
||||||
|
|
||||||
// select word
|
// select word
|
||||||
|
if (forward)
|
||||||
moveToWordEnd(1, simple);
|
moveToWordEnd(1, simple);
|
||||||
|
else
|
||||||
|
moveToWordStart(1, simple, false);
|
||||||
|
|
||||||
// select trailing spaces if no leading space
|
// select trailing spaces if no leading space
|
||||||
if (!leadingSpace && document()->characterAt(position() + 1).isSpace()
|
if (!leadingSpace && document()->characterAt(position() + direction).isSpace()
|
||||||
&& !atBlockStart()) {
|
&& !atBlockStart()) {
|
||||||
|
if (forward)
|
||||||
moveToNextBoundaryEnd(1, simple);
|
moveToNextBoundaryEnd(1, simple);
|
||||||
|
else
|
||||||
|
moveToNextBoundaryStart(1, simple, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there are no trailing spaces in selection select all leading spaces
|
// 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) {
|
if (i + 1 < repeat) {
|
||||||
|
if (forward) {
|
||||||
moveRight();
|
moveRight();
|
||||||
if (atEndOfLine())
|
if (atEndOfLine())
|
||||||
moveRight();
|
moveRight();
|
||||||
|
} else {
|
||||||
|
moveLeft();
|
||||||
|
if (atBlockStart())
|
||||||
|
moveLeft();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6853,9 +6877,13 @@ void FakeVimHandler::Private::selectTextObject(bool simple, bool inner)
|
|||||||
m_movetype = MoveInclusive;
|
m_movetype = MoveInclusive;
|
||||||
} else {
|
} else {
|
||||||
m_movetype = MoveExclusive;
|
m_movetype = MoveExclusive;
|
||||||
|
if (isNoVisualMode()) {
|
||||||
moveRight();
|
moveRight();
|
||||||
if (atEndOfLine())
|
if (atEndOfLine())
|
||||||
moveRight();
|
moveRight();
|
||||||
|
} else if (isVisualLineMode()) {
|
||||||
|
m_visualMode = VisualCharMode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setTargetColumn();
|
setTargetColumn();
|
||||||
|
|||||||
Reference in New Issue
Block a user