From 2fb8590f8763cf321579632b3d3e903d019a0dfc Mon Sep 17 00:00:00 2001
From: hluk <hluk@email.cz>
Date: Tue, 14 May 2013 19:09:57 +0200
Subject: [PATCH] FakeVim: Fix behavior of 'dw' command

Task-number: QTCREATORBUG-9289
Change-Id: I7ac1c925a13df49d60db410dce2d90b02cac7cfd
Reviewed-by: hjk <hjk121@nokiamail.com>
---
 src/plugins/fakevim/fakevim_test.cpp   | 15 +++++++++++++++
 src/plugins/fakevim/fakevimhandler.cpp |  7 ++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/plugins/fakevim/fakevim_test.cpp b/src/plugins/fakevim/fakevim_test.cpp
index ae2a7a31c35..0cabd226acd 100644
--- a/src/plugins/fakevim/fakevim_test.cpp
+++ b/src/plugins/fakevim/fakevim_test.cpp
@@ -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()
diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp
index b288d73f8a0..7bebc74ddc0 100644
--- a/src/plugins/fakevim/fakevimhandler.cpp
+++ b/src/plugins/fakevim/fakevimhandler.cpp
@@ -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();
-- 
GitLab