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