Commit 0e6041ed authored by Lukas Holecek's avatar Lukas Holecek Committed by hjk

fakevim: Paragraph movement using '{' and '}'

Change-Id: Ie156438b6633b7e9680e028fca7eca1b8788a63d
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 6868fedf
......@@ -383,6 +383,25 @@ void FakeVimPlugin::test_vim_movement()
KEYS("A", "abc def" X N "ghi");
data.setText("abc def" N "ghi");
KEYS("$a", "abc def" X N "ghi");
// paragraph movement
data.setText("abc" N N "def");
KEYS("}", "abc" N X N "def");
KEYS("}", "abc" N N "de" X "f");
KEYS("{", "abc" N X N "def");
KEYS("{", X "abc" N N "def");
data.setText("abc" N N N N "def");
KEYS("}", "abc" N X N N N "def");
KEYS("}", "abc" N N N N "de" X "f");
KEYS("3{", "abc" N N N N "de" X "f");
KEYS("{", "abc" N N N X N "def");
KEYS("{", X "abc" N N N N "def");
KEYS("3}", X "abc" N N N N "def");
data.setText("abc def");
KEYS("}", "abc de" X "f");
KEYS("{", X "abc def");
}
void FakeVimPlugin::test_vim_insert()
......
......@@ -1530,6 +1530,9 @@ public:
EDITOR(setTextCursor(tc));
}
bool moveToPreviousParagraph(int count) { return moveToNextParagraph(-count); }
bool moveToNextParagraph(int count);
bool handleFfTt(QString key);
void enterInsertMode();
......@@ -2450,6 +2453,37 @@ void FakeVimHandler::Private::moveDown(int n)
moveToTargetColumn();
}
bool FakeVimHandler::Private::moveToNextParagraph(int count)
{
const bool forward = count > 0;
int repeat = forward ? count : -count;
QTextBlock block = this->block();
if (block.isValid() && block.length() == 1)
++repeat;
for (; block.isValid(); block = forward ? block.next() : block.previous()) {
if (block.length() == 1) {
if (--repeat == 0)
break;
while (block.isValid() && block.length() == 1)
block = forward ? block.next() : block.previous();
}
}
if (repeat == 0)
setPosition(block.position());
else if (repeat == 1)
setPosition(forward ? lastPositionInDocument() : 0);
else
return false;
setTargetColumn();
m_movetype = MoveExclusive;
return true;
}
void FakeVimHandler::Private::moveToEndOfLine()
{
// Additionally select (in visual mode) or apply current command on hidden lines following
......@@ -2986,6 +3020,10 @@ bool FakeVimHandler::Private::handleMovement(const Input &input)
moveToStartOfLine();
moveRight(qMin(count, rightDist()) - 1);
setTargetColumn();
} else if (input.is('}')) {
handled = moveToNextParagraph(count);
} else if (input.is('{')) {
handled = moveToPreviousParagraph(count);
} else if (input.isReturn()) {
moveToStartOfLine();
moveDown();
......
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