fakevim: Set correct cursor column after a command

Set cursor column after some commands and position the cursor on same
column after vertical movement. If line is too short set cursor to the
end of line but don't remember the new cursor column.

Change-Id: I4f5592925b9b360e7393f6ac966025f1466f483d
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
Lukas Holecek
2012-12-20 18:12:10 +01:00
committed by hjk
parent 01d6d5eac3
commit b74ae13491
3 changed files with 70 additions and 5 deletions

View File

@@ -1370,6 +1370,60 @@ void FakeVimPlugin::test_vim_jumps()
KEYS("<C-O>", "abc" N "def" N "g" X "hi"); KEYS("<C-O>", "abc" N "def" N "g" X "hi");
} }
void FakeVimPlugin::test_vim_current_column()
{
// Check if column is correct after command and vertical cursor movement.
TestData data;
setup(&data);
// always at end of line after <end>
data.setText(" abc" N " def 123" N "" N " ghi");
KEYS("<end><down>", " abc" N " def 12" X "3" N "" N " ghi");
KEYS("<down><down>", " abc" N " def 123" N "" N " gh" X "i");
KEYS("<up>", " abc" N " def 123" N X "" N " ghi");
KEYS("<up>", " abc" N " def 12" X "3" N "" N " ghi");
// ... in insert
KEYS("i<end><up>", " abc" X N " def 123" N "" N " ghi");
KEYS("<down>i<end><up><down>", " abc" N " def 123" X N "" N " ghi");
// vertical movement doesn't reset column
data.setText(" abc" N " def 1" X "23" N "" N " ghi");
KEYS("<up>", " ab" X "c" N " def 123" N "" N " ghi");
KEYS("<down>", " abc" N " def 1" X "23" N "" N " ghi");
KEYS("<down><down>", " abc" N " def 123" N "" N " gh" X "i");
KEYS("<up><up>", " abc" N " def 1" X "23" N "" N " ghi");
KEYS("^jj", " abc" N " def 123" N "" N " " X "ghi");
KEYS("kk", " abc" N " " X "def 123" N "" N " ghi");
// yiw, yaw
data.setText(" abc" N " def" N " ghi");
KEYS("e<down>", " abc" N " de" X "f" N " ghi");
KEYS("b<down>", " abc" N " def" N " " X "ghi");
KEYS("ll<up>", " abc" N " de" X "f" N " ghi");
KEYS("<down>yiw<up>", " abc" N " " X "def" N " ghi");
KEYS("llyaw<up>", " " X "abc" N " def" N " ghi");
// insert
data.setText(" abc" N " def" N " ghi");
KEYS("lljj", " abc" N " def" N " " X "ghi");
KEYS("i123<up>", " abc" N " def" X N " 123ghi");
KEYS("a456<up><down>", " abc" N " def456" X N " 123ghi");
data.setText(" abc" N X " def 123" N "" N " ghi");
KEYS("A<down><down>", " abc" N " def 123" N "" N " ghi" X);
KEYS("A<up><up>", " abc" N " def" X " 123" N "" N " ghi");
KEYS("A<down><down><up><up>", " abc" N " def 123" X N "" N " ghi");
data.setText(" abc" N X " def 123" N "" N " ghi");
KEYS("I<down><down>", " abc" N " def 123" N "" N " " X "ghi");
// change
data.setText(" abc" N " d" X "ef" N " ghi");
KEYS("cc<up>", " " X "abc" N " " N " ghi");
data.setText(" abc" N " d" X "ef" N " ghi");
KEYS("cc<up>x<down><down>", " xabc" N " " N " g" X "hi");
}
void FakeVimPlugin::test_vim_copy_paste() void FakeVimPlugin::test_vim_copy_paste()
{ {
TestData data; TestData data;

View File

@@ -2137,7 +2137,10 @@ void FakeVimHandler::Private::recordInsertion(const QString &insert)
m_lastInsertion += insert; m_lastInsertion += insert;
} }
m_oldPosition = position(); if (m_oldPosition != pos) {
m_oldPosition = pos;
setTargetColumn();
}
} }
void FakeVimHandler::Private::ensureCursorVisible() void FakeVimHandler::Private::ensureCursorVisible()
@@ -2707,11 +2710,10 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommandMovement)
if (m_rangemode == RangeLineMode) { if (m_rangemode == RangeLineMode) {
if (isVisualMode()) if (isVisualMode())
moveToStartOfLine(); moveToStartOfLine();
else
setTargetColumn();
} }
} }
leaveVisualMode(); leaveVisualMode();
setTargetColumn();
} else if (m_submode == InvertCaseSubMode } else if (m_submode == InvertCaseSubMode
|| m_submode == UpCaseSubMode || m_submode == UpCaseSubMode
|| m_submode == DownCaseSubMode) { || m_submode == DownCaseSubMode) {
@@ -3451,6 +3453,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
setUndoPosition(); setUndoPosition();
setAnchor(); setAnchor();
enterInsertMode(); enterInsertMode();
setTargetColumn();
setDotCommand(_("%1A"), count()); setDotCommand(_("%1A"), count());
} else if (input.isControl('a')) { } else if (input.isControl('a')) {
if (changeNumberTextObject(count())) if (changeNumberTextObject(count()))
@@ -3561,6 +3564,7 @@ bool FakeVimHandler::Private::handleNoSubMode(const Input &input)
setUndoPosition(); setUndoPosition();
breakEditBlock(); breakEditBlock();
enterInsertMode(); enterInsertMode();
setTargetColumn();
} else if (input.isControl('i')) { } else if (input.isControl('i')) {
jump(count()); jump(count());
} else if (input.is('J')) { } else if (input.is('J')) {
@@ -4029,9 +4033,11 @@ EventResult FakeVimHandler::Private::handleReplaceMode(const Input &input)
} else if (input.isKey(Key_Left)) { } else if (input.isKey(Key_Left)) {
breakEditBlock(); breakEditBlock();
moveLeft(1); moveLeft(1);
setTargetColumn();
} else if (input.isKey(Key_Right)) { } else if (input.isKey(Key_Right)) {
breakEditBlock(); breakEditBlock();
moveRight(1); moveRight(1);
setTargetColumn();
} else if (input.isKey(Key_Up)) { } else if (input.isKey(Key_Up)) {
breakEditBlock(); breakEditBlock();
moveUp(1); moveUp(1);
@@ -4059,7 +4065,6 @@ EventResult FakeVimHandler::Private::handleReplaceMode(const Input &input)
recordInsertion(); recordInsertion();
} }
m_oldPosition = position(); m_oldPosition = position();
setTargetColumn();
updateMiniBuffer(); updateMiniBuffer();
return EventHandled; return EventHandled;
@@ -4145,9 +4150,11 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
} else if (input.isKey(Key_Left)) { } else if (input.isKey(Key_Left)) {
moveLeft(count()); moveLeft(count());
move = true; move = true;
setTargetColumn();
} else if (input.isControl(Key_Left)) { } else if (input.isControl(Key_Left)) {
moveToNextWordStart(count(), false, false); moveToNextWordStart(count(), false, false);
move = true; move = true;
setTargetColumn();
} else if (input.isKey(Key_Down)) { } else if (input.isKey(Key_Down)) {
//removeAutomaticIndentation(); //removeAutomaticIndentation();
m_submode = NoSubMode; m_submode = NoSubMode;
@@ -4161,18 +4168,22 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
} else if (input.isKey(Key_Right)) { } else if (input.isKey(Key_Right)) {
moveRight(count()); moveRight(count());
move = true; move = true;
setTargetColumn();
} else if (input.isControl(Key_Right)) { } else if (input.isControl(Key_Right)) {
moveToNextWordStart(count(), false, true); moveToNextWordStart(count(), false, true);
moveRight(); // we need one more move since we are in insert mode moveRight(); // we need one more move since we are in insert mode
move = true; move = true;
setTargetColumn();
} else if (input.isKey(Key_Home)) { } else if (input.isKey(Key_Home)) {
moveToStartOfLine(); moveToStartOfLine();
move = true; move = true;
setTargetColumn();
} else if (input.isKey(Key_End)) { } else if (input.isKey(Key_End)) {
if (count() > 1) if (count() > 1)
moveDown(count() - 1); moveDown(count() - 1);
moveBehindEndOfLine(); moveBehindEndOfLine();
move = true; move = true;
setTargetColumn();
} else if (input.isReturn() || input.isControl('j') || input.isControl('m')) { } else if (input.isReturn() || input.isControl('j') || input.isControl('m')) {
joinPreviousEditBlock(); joinPreviousEditBlock();
m_submode = NoSubMode; m_submode = NoSubMode;
@@ -4277,7 +4288,6 @@ EventResult FakeVimHandler::Private::handleInsertMode(const Input &input)
m_lastInsertion.clear(); m_lastInsertion.clear();
recordInsertion(insert); recordInsertion(insert);
} }
setTargetColumn();
updateMiniBuffer(); updateMiniBuffer();
return EventHandled; return EventHandled;

View File

@@ -75,6 +75,7 @@ private slots:
void test_vim_indent(); void test_vim_indent();
void test_vim_marks(); void test_vim_marks();
void test_vim_jumps(); void test_vim_jumps();
void test_vim_current_column();
void test_vim_copy_paste(); void test_vim_copy_paste();
void test_vim_undo_redo(); void test_vim_undo_redo();
void test_vim_letter_case(); void test_vim_letter_case();