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