fakevim: fix positioning after 'w'

was broken during the changes to the "target column" logic
This commit is contained in:
hjk
2009-04-09 16:20:49 +02:00
parent e76ba64f68
commit 3e6285358d
2 changed files with 62 additions and 11 deletions

View File

@@ -50,6 +50,7 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QFile> #include <QtCore/QFile>
#include <QtCore/QObject> #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) static int charClass(QChar c, bool simple)
{ {
if (simple) if (simple)
@@ -2066,6 +2075,7 @@ void FakeVimHandler::Private::moveToWordBoundary(bool simple, bool forward)
int lastClass = -1; int lastClass = -1;
while (true) { while (true) {
QChar c = doc->characterAt(m_tc.position() + (forward ? 1 : -1)); QChar c = doc->characterAt(m_tc.position() + (forward ? 1 : -1));
qDebug() << "EXAMINING: " << c << " AT " << position();
int thisClass = charClass(c, simple); int thisClass = charClass(c, simple);
if (thisClass != lastClass && lastClass != 0) if (thisClass != lastClass && lastClass != 0)
--repeat; --repeat;
@@ -2076,6 +2086,7 @@ void FakeVimHandler::Private::moveToWordBoundary(bool simple, bool forward)
break; break;
forward ? moveRight() : moveLeft(); forward ? moveRight() : moveLeft();
} }
setTargetColumn();
} }
void FakeVimHandler::Private::handleFfTt(int key) void FakeVimHandler::Private::handleFfTt(int key)
@@ -2111,6 +2122,7 @@ void FakeVimHandler::Private::handleFfTt(int key)
break; break;
} }
} }
setTargetColumn();
} }
void FakeVimHandler::Private::moveToNextWord(bool simple) void FakeVimHandler::Private::moveToNextWord(bool simple)
@@ -2131,6 +2143,7 @@ void FakeVimHandler::Private::moveToNextWord(bool simple)
if (m_tc.position() == n) if (m_tc.position() == n)
break; break;
} }
setTargetColumn();
} }
void FakeVimHandler::Private::moveToMatchingParanthesis() void FakeVimHandler::Private::moveToMatchingParanthesis()
@@ -2144,6 +2157,7 @@ void FakeVimHandler::Private::moveToMatchingParanthesis()
if (m_submode == NoSubMode || m_submode == ZSubMode || m_submode == RegisterSubMode) if (m_submode == NoSubMode || m_submode == ZSubMode || m_submode == RegisterSubMode)
m_tc.movePosition(Left, KeepAnchor, 1); m_tc.movePosition(Left, KeepAnchor, 1);
} }
setTargetColumn();
} }
int FakeVimHandler::Private::cursorLineOnScreen() const int FakeVimHandler::Private::cursorLineOnScreen() const

View File

@@ -55,10 +55,13 @@ public slots:
void changeExtraInformation(const QString &info) { m_infoMessage = info; } void changeExtraInformation(const QString &info) { m_infoMessage = info; }
private slots: private slots:
void commandI();
void commandDollar(); void commandDollar();
void commandDown(); void commandDown();
void commandLeft();
void commandRight();
void commandI();
void commandUp(); void commandUp();
void commandW();
private: private:
void setup(); void setup();
@@ -203,6 +206,10 @@ bool tst_FakeVim::checkHelper(bool ex, QString cmd, QString expected,
do { if (!checkHelper(false, cmd, expected, __FILE__, __LINE__)) \ do { if (!checkHelper(false, cmd, expected, __FILE__, __LINE__)) \
return; } while (0) 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. // Runs an ex command and checks the result.
// Cursor position is marked by a '@' in the expected contents. // Cursor position is marked by a '@' in the expected contents.
#define checkEx(cmd, expected) \ #define checkEx(cmd, expected) \
@@ -251,27 +258,57 @@ void tst_FakeVim::commandI()
void tst_FakeVim::commandDollar() void tst_FakeVim::commandDollar()
{ {
setup(); setup();
check("j$", insertCursor("<QtCore>@")); move("j$", "<QtCore>@");
check("j$", insertCursor("<QtGui>@")); move("j$", "<QtGui>@");
check("2j", insertCursor(")@")); move("2j", ")@");
} }
void tst_FakeVim::commandDown() void tst_FakeVim::commandDown()
{ {
setup(); setup();
check("j", insertCursor("@#include <QtCore")); move("j", "@#include <QtCore");
check("3j", insertCursor("@int main")); move("3j", "@int main");
check("4j", insertCursor("@ return app.exec()")); move("4j", "@ return app.exec()");
} }
void tst_FakeVim::commandUp() void tst_FakeVim::commandUp()
{ {
setup(); setup();
check("j", insertCursor("@#include <QtCore")); move("j", "@#include <QtCore");
check("3j", insertCursor("@int main")); move("3j", "@int main");
check("4j", insertCursor("@ return app.exec()")); 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 <QtCore>
#include <QtGui> #include <QtGui>