From 978fa5d03de1bac9cb65280a9158358722d60af6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Aum=C3=BCller?= <aumuell@reserv.at>
Date: Thu, 21 Jan 2010 17:38:30 +0100
Subject: [PATCH] fakevim: fix 'dw' at line-end

Merge-request: 99
Reviewed-by: hjk <qtc-committer@nokia.com>
---
 src/plugins/fakevim/fakevimhandler.cpp | 17 +++++++++++------
 tests/auto/fakevim/main.cpp            |  3 +--
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp
index 39697b68fe8..d14b4433679 100755
--- a/src/plugins/fakevim/fakevimhandler.cpp
+++ b/src/plugins/fakevim/fakevimhandler.cpp
@@ -347,7 +347,7 @@ public:
         m_targetColumn = leftDist();
         //qDebug() << "TARGET: " << m_targetColumn;
     }
-    void moveToNextWord(bool simple);
+    void moveToNextWord(bool simple, bool deleteWord = false);
     void moveToMatchingParanthesis();
     void moveToWordBoundary(bool simple, bool forward, bool changeWord = false);
 
@@ -1701,7 +1701,7 @@ EventResult FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
             moveToWordBoundary(false, true, true);
             m_movetype = MoveInclusive;
         } else {
-            moveToNextWord(false);
+            moveToNextWord(false, m_submode==DeleteSubMode);
             m_movetype = MoveExclusive;
         }
         finishMovement("%1w", count());
@@ -1710,7 +1710,7 @@ EventResult FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
             moveToWordBoundary(true, true, true);
             m_movetype = MoveInclusive;
         } else {
-            moveToNextWord(true);
+            moveToNextWord(true, m_submode==DeleteSubMode);
             m_movetype = MoveExclusive;
         }
         finishMovement("%1W", count());
@@ -2743,7 +2743,7 @@ void FakeVimHandler::Private::handleFfTt(int key)
     setTargetColumn();
 }
 
-void FakeVimHandler::Private::moveToNextWord(bool simple)
+void FakeVimHandler::Private::moveToNextWord(bool simple, bool deleteWord)
 {
     int repeat = count();
     int n = lastPositionInDocument();
@@ -2757,8 +2757,13 @@ void FakeVimHandler::Private::moveToNextWord(bool simple)
             break;
         lastClass = thisClass;
         moveRight();
-        if (m_tc.block().length() == 1) // empty line
-            --repeat;
+        if (deleteWord) {
+            if (m_tc.atBlockEnd())
+                --repeat;
+        } else {
+            if (m_tc.block().length() == 1) // empty line
+                --repeat;
+        }
         if (repeat == 0)
             break;
         if (m_tc.position() == n)
diff --git a/tests/auto/fakevim/main.cpp b/tests/auto/fakevim/main.cpp
index fab7e973d76..2815ad86cb7 100644
--- a/tests/auto/fakevim/main.cpp
+++ b/tests/auto/fakevim/main.cpp
@@ -439,8 +439,7 @@ void tst_FakeVim::command_dw()
     check("dw",  "@<QtCore>\n" + lmid(2));
     check("dw",  "@QtCore>\n" + lmid(2));
     check("dw",  "@>\n" + lmid(2));
-    qWarning("FIXME");
-    //check("dw",  "@\n" + lmid(2)); // FIXME: Real vim has this intermediate step
+    check("dw",  "@\n" + lmid(2)); // Real vim has this intermediate step, too
     check("dw",  "@#include <QtGui>\n" + lmid(3));
     check("dw",  "@include <QtGui>\n" + lmid(3));
     check("dw",  "@<QtGui>\n" + lmid(3));
-- 
GitLab