Commit 709c1427 authored by Lukas Holecek's avatar Lukas Holecek Committed by hjk

fakevim: Fix commands ci* and di*

Commands ciw and diw should work on a single character.

Commands ci), di" and similar should work on in an empty block.

Change-Id: Id166a3fb80fc5ba2672231638ce126bd88b4f3ff
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 97bcf9ea
......@@ -616,6 +616,10 @@ void FakeVimPlugin::test_vim_delete_inner_word()
KEYS("3diw", "x" N X "" N " ");
data.setText("x" N X "" N "" N "" N "" N "" N "" N " ");
KEYS("4diw", "x" N X "" N " ");
// delete single-character-word
data.setText("a " X "b c");
KEYS("diw", "a " X " c");
}
void FakeVimPlugin::test_vim_delete_a_word()
......@@ -662,6 +666,10 @@ void FakeVimPlugin::test_vim_delete_a_word()
KEYS("2daw", "x" N X "" N " ");
data.setText("x" N X "" N "" N "" N "" N "" N "" N " ");
KEYS("3daw", "x" N " " X " ");
// delete single-character-word
data.setText("a," X "b,c");
KEYS("daw", "a," X ",c");
}
void FakeVimPlugin::test_vim_change_a_word()
......@@ -689,6 +697,11 @@ void FakeVimPlugin::test_vim_change_a_word()
data.setText(" abc " N " def" N " ghi" N " jkl");
KEYS("3caw#", "#" X N " jkl");
// change single-character-word
data.setText("a " X "b c");
KEYS("ciwX<esc>", "a " X "X c");
KEYS("cawZ<esc>", "a " X "Zc");
}
void FakeVimPlugin::test_vim_change_replace()
......
......@@ -1423,9 +1423,10 @@ public:
void selectWORDTextObject(bool inner);
void selectSentenceTextObject(bool inner);
void selectParagraphTextObject(bool inner);
void selectBlockTextObject(bool inner, char left, char right);
void changeNumberTextObject(int count);
void selectQuotedStringTextObject(bool inner, const QString &quote);
// return true only if cursor is in a block delimited with correct characters
bool selectBlockTextObject(bool inner, char left, char right);
bool selectQuotedStringTextObject(bool inner, const QString &quote);
Q_SLOT void importSelection();
void exportSelection();
......@@ -2636,6 +2637,7 @@ EventResult FakeVimHandler::Private::handleCommandSubSubMode(const Input &input)
.arg(m_semicolonKey));
}
} else if (m_subsubmode == TextObjectSubSubMode) {
bool ok = true;
if (input.is('w'))
selectWordTextObject(m_subsubdata.is('i'));
else if (input.is('W'))
......@@ -2645,17 +2647,17 @@ EventResult FakeVimHandler::Private::handleCommandSubSubMode(const Input &input)
else if (input.is('p'))
selectParagraphTextObject(m_subsubdata.is('i'));
else if (input.is('[') || input.is(']'))
selectBlockTextObject(m_subsubdata.is('i'), '[', ']');
ok = selectBlockTextObject(m_subsubdata.is('i'), '[', ']');
else if (input.is('(') || input.is(')') || input.is('b'))
selectBlockTextObject(m_subsubdata.is('i'), '(', ')');
ok = selectBlockTextObject(m_subsubdata.is('i'), '(', ')');
else if (input.is('<') || input.is('>'))
selectBlockTextObject(m_subsubdata.is('i'), '<', '>');
ok = selectBlockTextObject(m_subsubdata.is('i'), '<', '>');
else if (input.is('{') || input.is('}') || input.is('B'))
selectBlockTextObject(m_subsubdata.is('i'), '{', '}');
ok = selectBlockTextObject(m_subsubdata.is('i'), '{', '}');
else if (input.is('"') || input.is('\'') || input.is('`'))
selectQuotedStringTextObject(m_subsubdata.is('i'), input.asChar());
ok = selectQuotedStringTextObject(m_subsubdata.is('i'), input.asChar());
m_subsubmode = NoSubSubMode;
if (cursor().hasSelection()) {
if (ok) {
finishMovement(QString("%1%2%3")
.arg(count())
.arg(m_subsubdata.text())
......@@ -6445,7 +6447,7 @@ void FakeVimHandler::Private::selectParagraphTextObject(bool inner)
Q_UNUSED(inner);
}
void FakeVimHandler::Private::selectBlockTextObject(bool inner,
bool FakeVimHandler::Private::selectBlockTextObject(bool inner,
char left, char right)
{
QString sleft = QString(QLatin1Char(left));
......@@ -6453,21 +6455,22 @@ void FakeVimHandler::Private::selectBlockTextObject(bool inner,
int p1 = blockBoundary(sleft, sright, false, count());
if (p1 == -1)
return;
return false;
int p2 = blockBoundary(sleft, sright, true, count());
if (p2 == -1)
return;
return false;
if (inner) {
p1 += sleft.size();
p2 = qMax(p1, p2 - 1);
} else {
p2 -= sright.size() - 1;
p2 -= sright.size() - 2;
}
setAnchorAndPosition(p1, p2);
m_movetype = MoveInclusive;
m_movetype = MoveExclusive;
return true;
}
static bool isSign(const QChar c)
......@@ -6506,7 +6509,7 @@ void FakeVimHandler::Private::changeNumberTextObject(int count)
setPosition(p1 + repl.size() - 1);
}
void FakeVimHandler::Private::selectQuotedStringTextObject(bool inner,
bool FakeVimHandler::Private::selectQuotedStringTextObject(bool inner,
const QString &quote)
{
QTextCursor tc = cursor();
......@@ -6517,25 +6520,27 @@ void FakeVimHandler::Private::selectQuotedStringTextObject(bool inner,
while (tc2 <= tc) {
tc1 = document()->find(quote, tc2);
if (tc1.isNull() || tc1.anchor() > tc.position())
return;
return false;
tc2 = document()->find(quote, tc1);
if (tc2.isNull())
return;
return false;
}
int p1 = tc1.position();
int p2 = tc2.position();
if (inner) {
p2 = qMax(p1, p2 - sz - 1);
p2 = qMax(p1, p2 - sz);
if (document()->characterAt(p1) == ParagraphSeparator)
++p1;
} else {
p1 -= sz;
p2 -= sz;
p2 -= sz - 1;
}
setAnchorAndPosition(p1, p2);
m_movetype = MoveInclusive;
m_movetype = MoveExclusive;
return true;
}
Mark FakeVimHandler::Private::mark(QChar code) const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment