Commit 3e628535 authored by hjk's avatar hjk
Browse files

fakevim: fix positioning after 'w'

was broken during the changes to the "target column" logic
parent e76ba64f
......@@ -50,6 +50,7 @@
#include <utils/qtcassert.h>
#include <QtCore/QDebug>
#include <QtCore/QFile>
#include <QtCore/QObject>
......@@ -2049,6 +2050,14 @@ void FakeVimHandler::Private::moveToTargetColumn()
}
}
/* if simple is given:
* class 0: spaces
* class 1: non-spaces
* else
* class 0: spaces
* class 1: non-space-or-letter-or-number
* class 2: letter-or-number
*/
static int charClass(QChar c, bool simple)
{
if (simple)
......@@ -2066,6 +2075,7 @@ void FakeVimHandler::Private::moveToWordBoundary(bool simple, bool forward)
int lastClass = -1;
while (true) {
QChar c = doc->characterAt(m_tc.position() + (forward ? 1 : -1));
qDebug() << "EXAMINING: " << c << " AT " << position();
int thisClass = charClass(c, simple);
if (thisClass != lastClass && lastClass != 0)
--repeat;
......@@ -2076,6 +2086,7 @@ void FakeVimHandler::Private::moveToWordBoundary(bool simple, bool forward)
break;
forward ? moveRight() : moveLeft();
}
setTargetColumn();
}
void FakeVimHandler::Private::handleFfTt(int key)
......@@ -2111,6 +2122,7 @@ void FakeVimHandler::Private::handleFfTt(int key)
break;
}
}
setTargetColumn();
}
void FakeVimHandler::Private::moveToNextWord(bool simple)
......@@ -2131,6 +2143,7 @@ void FakeVimHandler::Private::moveToNextWord(bool simple)
if (m_tc.position() == n)
break;
}
setTargetColumn();
}
void FakeVimHandler::Private::moveToMatchingParanthesis()
......@@ -2144,6 +2157,7 @@ void FakeVimHandler::Private::moveToMatchingParanthesis()
if (m_submode == NoSubMode || m_submode == ZSubMode || m_submode == RegisterSubMode)
m_tc.movePosition(Left, KeepAnchor, 1);
}
setTargetColumn();
}
int FakeVimHandler::Private::cursorLineOnScreen() const
......
......@@ -55,10 +55,13 @@ public slots:
void changeExtraInformation(const QString &info) { m_infoMessage = info; }
private slots:
void commandI();
void commandDollar();
void commandDown();
void commandLeft();
void commandRight();
void commandI();
void commandUp();
void commandW();
private:
void setup();
......@@ -203,6 +206,10 @@ bool tst_FakeVim::checkHelper(bool ex, QString cmd, QString expected,
do { if (!checkHelper(false, cmd, expected, __FILE__, __LINE__)) \
return; } while (0)
#define move(cmd, expected) \
do { if (!checkHelper(false, cmd, insertCursor(expected), __FILE__, __LINE__)) \
return; } while (0)
// Runs an ex command and checks the result.
// Cursor position is marked by a '@' in the expected contents.
#define checkEx(cmd, expected) \
......@@ -235,7 +242,7 @@ void tst_FakeVim::commandI()
check("ixxx" + escape, "xx@x" + lines);
check("u", "@" + lines);
return;
return;
// combine insertions
check("ia" + escape, "@a" + lines);
......@@ -251,27 +258,57 @@ void tst_FakeVim::commandI()
void tst_FakeVim::commandDollar()
{
setup();
check("j$", insertCursor("<QtCore>@"));
check("j$", insertCursor("<QtGui>@"));
check("2j", insertCursor(")@"));
move("j$", "<QtCore>@");
move("j$", "<QtGui>@");
move("2j", ")@");
}
void tst_FakeVim::commandDown()
{
setup();
check("j", insertCursor("@#include <QtCore"));
check("3j", insertCursor("@int main"));
check("4j", insertCursor("@ return app.exec()"));
move("j", "@#include <QtCore");
move("3j", "@int main");
move("4j", "@ return app.exec()");
}
void tst_FakeVim::commandUp()
{
setup();
check("j", insertCursor("@#include <QtCore"));
check("3j", insertCursor("@int main"));
check("4j", insertCursor("@ return app.exec()"));
move("j", "@#include <QtCore");
move("3j", "@int main");
move("4j", "@ return app.exec()");
}
void tst_FakeVim::commandRight()
{
setup();
move("4j", "@int main");
move("l", "i@nt main");
move("3l", "int @main");
move("50l", "argv[])@");
}
void tst_FakeVim::commandLeft()
{
setup();
move("4j", "@int main");
move("h", "@int main"); // no move over left border
move("$", "argv[])@");
move("h", "argv[]@)");
move("3h", "arg@v[])");
move("50h", "@int main");
}
void tst_FakeVim::commandW()
{
setup();
move("w", "@#include <QtCore");
move("w", "#@include <QtCore");
move("w", "#include @<QtCore");
move("3w", "@#include <QtGui");
}
/*
#include <QtCore>
#include <QtGui>
......
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