Commit 0e83172b authored by Lukas Holecek's avatar Lukas Holecek Committed by hjk
Browse files

FakeVim: Indent block correctly



In situation:

    void f() {
    // Cursor is HERE.
    }

the code after ">i{" command is indented as (with shiftwidth=4):

    void f() {
        // Cursor is HERE.
    }

Change-Id: I48283c91c32fc407bbdb24349f2491461e401ee9
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 5881f6cb
......@@ -1829,6 +1829,59 @@ void FakeVimPlugin::test_vim_indent()
data.setText("abc");
KEYS(">>", "\t\t abc");
INTEGRITY(false);
// indent inner block
data.doCommand("set expandtab");
data.doCommand("set shiftwidth=2");
data.setText("int main()" N
"{" N
"int i = 0;" N
X "return i;" N
"}" N
"");
KEYS(">i{",
"int main()" N
"{" N
" " X "int i = 0;" N
" return i;" N
"}" N
"");
KEYS(">i}",
"int main()" N
"{" N
" " X "int i = 0;" N
" return i;" N
"}" N
"");
KEYS("<i}",
"int main()" N
"{" N
" " X "int i = 0;" N
" return i;" N
"}" N
"");
data.doCommand("set expandtab");
data.doCommand("set shiftwidth=2");
data.setText("int main() {" N
"return i;" N
X "}" N
"");
KEYS("l>i{",
"int main() {" N
" " X "return i;" N
"}" N
"");
KEYS("l>i}",
"int main() {" N
" " X "return i;" N
"}" N
"");
KEYS("l<i}",
"int main() {" N
" " X "return i;" N
"}" N
"");
}
void FakeVimPlugin::test_vim_marks()
......
......@@ -3377,12 +3377,17 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommandMovement)
|| g.submode == YankSubMode
|| g.submode == InvertCaseSubMode
|| g.submode == DownCaseSubMode
|| g.submode == UpCaseSubMode) {
|| g.submode == UpCaseSubMode
|| g.submode == IndentSubMode
|| g.submode == ShiftLeftSubMode
|| g.submode == ShiftRightSubMode)
{
fixSelection();
if (g.submode != InvertCaseSubMode
&& g.submode != DownCaseSubMode
&& g.submode != UpCaseSubMode) {
if (g.submode == ChangeSubMode
|| g.submode == DeleteSubMode
|| g.submode == YankSubMode)
{
yankText(currentRange(), m_register);
}
}
......@@ -8133,16 +8138,26 @@ bool FakeVimHandler::Private::selectBlockTextObject(bool inner,
if (p2 == -1)
return false;
if (inner)
g.movetype = MoveExclusive;
if (inner) {
p1 += sleft.size();
else
bool moveStart = characterAt(p1) == ParagraphSeparator;
bool moveEnd = isFirstNonBlankOnLine(p2);
if (moveStart)
++p1;
if (moveEnd)
p2 = blockAt(p2).position() - 1;
if (moveStart && moveEnd)
g.movetype = MoveLineWise;
} else {
p2 -= sright.size() - 2;
}
if (isVisualMode())
--p2;
setAnchorAndPosition(p1, p2);
g.movetype = MoveExclusive;
return true;
}
......
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