From a04137f39a3898c4443a4c72c57a5e79c2b98809 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Aum=C3=BCller?= <aumuell@reserv.at>
Date: Tue, 5 Jan 2010 18:42:26 +0100
Subject: [PATCH] fakevim: 'dG' at the end of the document should delete the
 last line

make sure that when deleting line-wise, a complete line is deleted,
even at the end of the document

Merge-request: 96
Reviewed-by: hjk <qtc-committer@nokia.com>
---
 src/plugins/fakevim/fakevimhandler.cpp | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp
index 7085d8dc555..713c9baaec0 100755
--- a/src/plugins/fakevim/fakevimhandler.cpp
+++ b/src/plugins/fakevim/fakevimhandler.cpp
@@ -817,6 +817,8 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommand)
         if (m_movetype == MoveLineWise)
             m_registers[m_register].rangemode = RangeLineMode;
         removeSelectedText();
+        if (m_movetype == MoveLineWise)
+            handleStartOfLine();
         m_submode = NoSubMode;
         if (atEndOfLine())
             moveLeft();
@@ -2769,7 +2771,21 @@ void FakeVimHandler::Private::removeText(const Range &range)
             tc.movePosition(StartOfLine, MoveAnchor);
             tc.setPosition(range.endPos, KeepAnchor);
             tc.movePosition(EndOfLine, KeepAnchor);
-            tc.movePosition(Right, KeepAnchor, 1);
+            // make sure that complete lines are removed
+            // - also at the beginning and at the end of the document
+            if (tc.atEnd()) {
+                tc.setPosition(range.beginPos, MoveAnchor);
+                tc.movePosition(StartOfLine, MoveAnchor);
+                if (!tc.atStart()) {
+                    // also remove first line if it is the only one
+                    tc.movePosition(Left, MoveAnchor, 1);
+                    tc.movePosition(EndOfLine, MoveAnchor, 1);
+                }
+                tc.setPosition(range.endPos, KeepAnchor);
+                tc.movePosition(EndOfLine, KeepAnchor);
+            } else {
+                tc.movePosition(Right, KeepAnchor, 1);
+            }
             fixMarks(range.beginPos, tc.selectionStart() - tc.selectionEnd());
             tc.removeSelectedText();
             return;
-- 
GitLab