Commit 37c3dbc5 authored by Lukas Holecek's avatar Lukas Holecek Committed by hjk

fakevim: Fix text indentation commands

Fixed indentation commands with movement and correct behavior in tests.

Change-Id: Idb77427c556f54c75658f806bb6c94402cab52ea
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 3e6ac654
......@@ -518,11 +518,10 @@ void FakeVimPlugin::test_vim_indent()
" jkl" N
"mno");
NOT_IMPLEMENTED
KEYS("2<<",
"abc" N
" " X "def" N
" ghi" N
" def" N
" " X "ghi" N
" jkl" N
"mno");
KEYS("k3<<",
......@@ -552,14 +551,18 @@ void FakeVimPlugin::test_vim_indent()
data.doCommand("set shiftwidth=2");
KEYS(">>", " " X "abc");
/* possibly QTCREATORBUG-7376 */
data.setText("abc");
data.doCommand("set noexpandtab");
data.doCommand("set tabstop=2");
data.doCommand("set shiftwidth=5");
data.doCommand("set shiftwidth=7");
// shiftwidth = TABS * tabstop + SPACES
// 7 = 3 * 2 + 1
KEYS(">>", "\t\t\t abc");
data.doCommand("set tabstop=3");
data.doCommand("set shiftwidth=7");
data.setText("abc");
KEYS(">>", "\t\t abc");
}
void FakeVimPlugin::test_vim_marks()
......@@ -694,6 +697,15 @@ void FakeVimPlugin::test_vim_undo_redo()
KEYS("<C-r>", "ab" X "c" N "def");
KEYS("<C-r>", "ab" X "c" N "def");
data.setText("abc" N "def");
KEYS("2>>", " " X "abc" N " def");
KEYS("u", X "abc" N "def");
KEYS("<c-r>", X " abc" N " def");
KEYS("u", X "abc" N "def");
KEYS(">j", " " X "abc" N " def");
KEYS("u", X "abc" N "def");
KEYS("<c-r>", X " abc" N " def");
// undo replace line
data.setText("abc" N " def" N "ghi");
KEYS("jlllSxyz<ESC>", "abc" N "xyz" N "ghi");
......
......@@ -2105,6 +2105,11 @@ void FakeVimHandler::Private::setUndoPosition(bool overwrite)
pos = firstPositionInLine(lineForPosition(pos));
} else if (m_movetype == MoveLineWise && hasConfig(ConfigStartOfLine)) {
QTextCursor tc = cursor();
if (m_submode == ShiftLeftSubMode || m_submode == ShiftRightSubMode
|| m_submode == IndentSubMode) {
pos = qMin(pos, anchor());
}
tc.setPosition(pos);
moveToFirstNonBlankOnLine(&tc);
pos = qMin(pos, tc.position());
}
......@@ -2314,16 +2319,22 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommand)
setUndoPosition();
indentSelectedText();
m_submode = NoSubMode;
if (!dotCommand.isEmpty())
setDotCommand('=' + dotCommand);
} else if (m_submode == ShiftRightSubMode) {
recordJump();
setUndoPosition();
shiftRegionRight(1);
m_submode = NoSubMode;
if (!dotCommand.isEmpty())
setDotCommand('>' + dotCommand);
} else if (m_submode == ShiftLeftSubMode) {
recordJump();
setUndoPosition();
shiftRegionLeft(1);
m_submode = NoSubMode;
if (!dotCommand.isEmpty())
setDotCommand('<' + dotCommand);
}
resetCommandMode();
......@@ -2647,26 +2658,13 @@ EventResult FakeVimHandler::Private::handleCommandMode(const Input &input)
&& (input.is('a') || input.is('i'))) {
m_subsubmode = TextObjectSubSubMode;
m_subsubdata = input;
} else if (m_submode == ShiftLeftSubMode && input.is('<')) {
m_movetype = MoveLineWise;
setUndoPosition();
setAnchor();
moveDown(count() - 1);
setDotCommand("%1<<", count());
finishMovement();
} else if (m_submode == ShiftRightSubMode && input.is('>')) {
} else if ((m_submode == ShiftLeftSubMode && input.is('<'))
|| (m_submode == ShiftRightSubMode && input.is('>'))
|| (m_submode == IndentSubMode && input.is('='))) {
m_movetype = MoveLineWise;
setUndoPosition();
setAnchor();
moveDown(count() - 1);
setDotCommand("%1>>", count());
finishMovement();
} else if (m_submode == IndentSubMode && input.is('=')) {
m_movetype = MoveLineWise;
setUndoPosition();
setAnchor();
moveDown(count() - 1);
setDotCommand("%1==", count());
setDotCommand(QString("%2%1%1").arg(input.asChar()), count());
finishMovement();
} else if (m_submode == ZSubMode) {
//qDebug() << "Z_MODE " << cursorLine() << linesOnScreen();
......@@ -2855,6 +2853,7 @@ EventResult FakeVimHandler::Private::handleCommandMode1(const Input &input)
} else if (input.is('<')) {
if (isNoVisualMode()) {
m_submode = ShiftLeftSubMode;
setAnchor();
} else {
shiftRegionLeft(count());
leaveVisualMode();
......@@ -2862,6 +2861,7 @@ EventResult FakeVimHandler::Private::handleCommandMode1(const Input &input)
} else if (input.is('>')) {
if (isNoVisualMode()) {
m_submode = ShiftRightSubMode;
setAnchor();
} else {
shiftRegionRight(count());
leaveVisualMode();
......@@ -2869,6 +2869,7 @@ EventResult FakeVimHandler::Private::handleCommandMode1(const Input &input)
} else if (input.is('=')) {
if (isNoVisualMode()) {
m_submode = IndentSubMode;
setAnchor();
} else {
indentSelectedText();
leaveVisualMode();
......
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