forked from qt-creator/qt-creator
partial implementation of 'e' and 'E'
This commit is contained in:
@@ -120,7 +120,9 @@ public:
|
|||||||
void scrollToLineInDocument(int line);
|
void scrollToLineInDocument(int line);
|
||||||
|
|
||||||
void moveToFirstNonBlankOnLine();
|
void moveToFirstNonBlankOnLine();
|
||||||
void moveWord(int repeat, bool simple);
|
void moveToNextWord(int repeat, bool simple);
|
||||||
|
void moveToWordBegin(int repeat, bool simple);
|
||||||
|
void moveToWordEnd(int repeat, bool simple);
|
||||||
|
|
||||||
FakeVimHandler *q;
|
FakeVimHandler *q;
|
||||||
Mode m_mode;
|
Mode m_mode;
|
||||||
@@ -301,6 +303,12 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
|
|||||||
} else if (key == 'A') {
|
} else if (key == 'A') {
|
||||||
m_tc.movePosition(EndOfLine, MoveAnchor);
|
m_tc.movePosition(EndOfLine, MoveAnchor);
|
||||||
m_mode = InsertMode;
|
m_mode = InsertMode;
|
||||||
|
} else if (key == 'b') {
|
||||||
|
moveToWordBegin(count(), false);
|
||||||
|
finishMovement();
|
||||||
|
} else if (key == 'B') {
|
||||||
|
moveToWordBegin(count(), true);
|
||||||
|
finishMovement();
|
||||||
} else if (key == 'c') {
|
} else if (key == 'c') {
|
||||||
m_submode = ChangeSubMode;
|
m_submode = ChangeSubMode;
|
||||||
} else if (key == 'C') {
|
} else if (key == 'C') {
|
||||||
@@ -315,6 +323,12 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
|
|||||||
m_submode = DeleteSubMode;
|
m_submode = DeleteSubMode;
|
||||||
m_tc.movePosition(EndOfLine, KeepAnchor);
|
m_tc.movePosition(EndOfLine, KeepAnchor);
|
||||||
finishMovement();
|
finishMovement();
|
||||||
|
} else if (key == 'e') {
|
||||||
|
moveToWordEnd(count(), false);
|
||||||
|
finishMovement();
|
||||||
|
} else if (key == 'E') {
|
||||||
|
moveToWordEnd(count(), true);
|
||||||
|
finishMovement();
|
||||||
} else if (key == 'h' || key == Key_Left) {
|
} else if (key == 'h' || key == Key_Left) {
|
||||||
int n = qMin(count(), leftDist());
|
int n = qMin(count(), leftDist());
|
||||||
if (m_fakeEnd && m_tc.block().length() > 1)
|
if (m_fakeEnd && m_tc.block().length() > 1)
|
||||||
@@ -370,10 +384,10 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text)
|
|||||||
} else if (key == 'u') {
|
} else if (key == 'u') {
|
||||||
m_editor->undo();
|
m_editor->undo();
|
||||||
} else if (key == 'w') {
|
} else if (key == 'w') {
|
||||||
moveWord(count(), false);
|
moveToNextWord(count(), false);
|
||||||
finishMovement();
|
finishMovement();
|
||||||
} else if (key == 'W') {
|
} else if (key == 'W') {
|
||||||
moveWord(count(), true);
|
moveToNextWord(count(), true);
|
||||||
finishMovement();
|
finishMovement();
|
||||||
} else if (key == 'x') { // = "dl"
|
} else if (key == 'x') { // = "dl"
|
||||||
if (atEol())
|
if (atEol())
|
||||||
@@ -528,7 +542,43 @@ static int charClass(QChar c, bool simple)
|
|||||||
return c.isSpace() ? 0 : 1;
|
return c.isSpace() ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimHandler::Private::moveWord(int repeat, bool simple)
|
void FakeVimHandler::Private::moveToWordBegin(int repeat, bool simple)
|
||||||
|
{
|
||||||
|
QTextDocument *doc = m_tc.document();
|
||||||
|
int n = lastPositionInDocument() - 1;
|
||||||
|
int lastClass = 0;
|
||||||
|
while (m_tc.position() < n) {
|
||||||
|
QChar c = doc->characterAt(m_tc.position());
|
||||||
|
int thisClass = charClass(c, simple);
|
||||||
|
if (thisClass != lastClass && thisClass != 0)
|
||||||
|
--repeat;
|
||||||
|
if (repeat == -1)
|
||||||
|
return;
|
||||||
|
lastClass = thisClass;
|
||||||
|
m_tc.movePosition(Right, KeepAnchor, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FakeVimHandler::Private::moveToWordEnd(int repeat, bool simple)
|
||||||
|
{
|
||||||
|
QTextDocument *doc = m_tc.document();
|
||||||
|
int n = lastPositionInDocument() - 1;
|
||||||
|
int lastClass = 0;
|
||||||
|
while (m_tc.position() < n) {
|
||||||
|
QChar c = doc->characterAt(m_tc.position());
|
||||||
|
int thisClass = charClass(c, simple);
|
||||||
|
if (thisClass != lastClass && lastClass != 0)
|
||||||
|
--repeat;
|
||||||
|
if (repeat == -1) {
|
||||||
|
m_tc.movePosition(Left, KeepAnchor, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lastClass = thisClass;
|
||||||
|
m_tc.movePosition(Right, KeepAnchor, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FakeVimHandler::Private::moveToNextWord(int repeat, bool simple)
|
||||||
{
|
{
|
||||||
// FIXME: 'w' should stop on empty lines, too
|
// FIXME: 'w' should stop on empty lines, too
|
||||||
QTextDocument *doc = m_tc.document();
|
QTextDocument *doc = m_tc.document();
|
||||||
|
|||||||
Reference in New Issue
Block a user