FakeVim: Fix behavior of 'dw' command

Task-number: QTCREATORBUG-9289
Change-Id: I7ac1c925a13df49d60db410dce2d90b02cac7cfd
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
hluk
2013-05-14 19:09:57 +02:00
committed by hjk
parent 80cef80910
commit 2fb8590f87
2 changed files with 21 additions and 1 deletions

View File

@@ -786,6 +786,21 @@ void FakeVimPlugin::test_vim_delete()
KEYS("\"xd$", X "" N "def");
KEYS("\"xp", "ab" X "c" N "def");
KEYS("2\"xp", "abcabcab" X "c" N "def");
/* QTCREATORBUG-9289 */
data.setText("abc" N "def");
KEYS("$" "dw", "a" X "b" N "def");
KEYS("dw", X "a" N "def");
KEYS("dw", X "" N "def");
KEYS("dw", X "def");
data.setText("abc" N "def ghi");
KEYS("2dw", X "ghi");
data.setText("abc" N X "" N "def");
KEYS("dw", "abc" N X "def");
KEYS("k$" "dw", "a" X "b" N "def");
KEYS("j$h" "dw", "ab" N X "d");
}
void FakeVimPlugin::test_vim_delete_inner_word()

View File

@@ -1505,7 +1505,7 @@ public:
bool atBlockStart() const { return m_cursor.atBlockStart(); }
bool atBlockEnd() const { return m_cursor.atBlockEnd(); }
bool atEndOfLine() const { return atBlockEnd() && block().length() > 1; }
bool atDocumentEnd() const { return position() >= lastPositionInDocument(); }
bool atDocumentEnd() const { return position() >= lastPositionInDocument(true); }
bool atDocumentStart() const { return m_cursor.atStart(); }
bool atEmptyLine(const QTextCursor &tc = QTextCursor()) const;
@@ -3507,6 +3507,11 @@ bool FakeVimHandler::Private::handleMovement(const Input &input)
m_movetype = MoveInclusive;
} else {
moveToNextWordStart(count, simple, true);
// Command 'dw' deletes to the next word on the same line or to end of line.
if (m_submode == DeleteSubMode && count == 1) {
const QTextBlock currentBlock = document()->findBlock(anchor());
setPosition(qMin(position(), currentBlock.position() + currentBlock.length()));
}
m_movetype = MoveExclusive;
}
setTargetColumn();