Commit 227ef824 authored by hluk's avatar hluk Committed by hjk

FakeVim: Command % jumps to first known parenthesis character

Change-Id: I28988925f397af8c4927c416774d7fe21e982dcb
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 8ea6a21a
......@@ -3025,6 +3025,90 @@ void FakeVimPlugin::test_vim_command_y_dollar()
KEYS("$y$P", l[0]+'\n'+ l[1]+">>|>>\n" + lmid(2));
}
void FakeVimPlugin::test_vim_command_percent()
{
TestData data;
setup(&data);
data.setText(
"bool f(int arg1) {" N
" Q_ASSERT(arg1 >= 0);" N
" if (arg1 > 0) return true; else if (arg1 <= 0) return false;" N
"}" N
);
KEYS("%",
"bool f(int arg1" X ") {" N
" Q_ASSERT(arg1 >= 0);" N
" if (arg1 > 0) return true; else if (arg1 <= 0) return false;" N
"}" N
);
KEYS("%",
"bool f" X "(int arg1) {" N
" Q_ASSERT(arg1 >= 0);" N
" if (arg1 > 0) return true; else if (arg1 <= 0) return false;" N
"}" N
);
KEYS("$h%",
"bool f(int arg1) {" N
" Q_ASSERT(arg1 >= 0);" N
" if (arg1 > 0) return true; else if (arg1 <= 0) return false;" N
X "}" N
);
KEYS("%",
"bool f(int arg1) " X "{" N
" Q_ASSERT(arg1 >= 0);" N
" if (arg1 > 0) return true; else if (arg1 <= 0) return false;" N
"}" N
);
KEYS("j%",
"bool f(int arg1) {" N
" Q_ASSERT" X "(arg1 >= 0);" N
" if (arg1 > 0) return true; else if (arg1 <= 0) return false;" N
"}" N
);
KEYS("%",
"bool f(int arg1) {" N
" Q_ASSERT(arg1 >= 0" X ");" N
" if (arg1 > 0) return true; else if (arg1 <= 0) return false;" N
"}" N
);
KEYS("j%",
"bool f(int arg1) {" N
" Q_ASSERT(arg1 >= 0);" N
" if (arg1 > 0) return true; else if (arg1 <= 0" X ") return false;" N
"}" N
);
KEYS("0%",
"bool f(int arg1) {" N
" Q_ASSERT(arg1 >= 0);" N
" if (arg1 > 0" X ") return true; else if (arg1 <= 0) return false;" N
"}" N
);
KEYS("%",
"bool f(int arg1) {" N
" Q_ASSERT(arg1 >= 0);" N
" if " X "(arg1 > 0) return true; else if (arg1 <= 0) return false;" N
"}" N
);
// jump to 50% of buffer
KEYS("50%",
"bool f(int arg1) {" N
" Q_ASSERT(arg1 >= 0);" N
" " X "if (arg1 > 0) return true; else if (arg1 <= 0) return false;" N
"}" N
);
}
void FakeVimPlugin::test_vim_command_Yp()
{
TestData data;
......
......@@ -6517,11 +6517,22 @@ void FakeVimHandler::Private::moveToMatchingParanthesis()
const int anc = anchor();
QTextCursor tc = m_cursor;
// If no known parenthesis symbol is under cursor find one on the current line after cursor.
static const QString parenthesesChars(_("([{}])"));
while (!parenthesesChars.contains(document()->characterAt(tc.position())) && !tc.atBlockEnd())
tc.setPosition(tc.position() + 1);
if (tc.atBlockEnd())
tc = m_cursor;
emit q->moveToMatchingParenthesis(&moved, &forward, &tc);
if (moved && forward)
tc.movePosition(Left, KeepAnchor, 1);
setAnchorAndPosition(anc, tc.position());
setTargetColumn();
if (moved) {
if (forward)
tc.movePosition(Left, KeepAnchor, 1);
setAnchorAndPosition(anc, tc.position());
setTargetColumn();
}
}
int FakeVimHandler::Private::cursorLineOnScreen() const
......
......@@ -136,6 +136,7 @@ private slots:
void test_vim_command_x();
void test_vim_command_yyp();
void test_vim_command_y_dollar();
void test_vim_command_percent();
void test_vim_visual_d();
void test_vim_Visual_d();
......
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