From 04731b79d9825bb947f81e2421ea04278ff2931b Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Fri, 20 Mar 2009 08:44:52 +0100
Subject: [PATCH] fakevim: implement Ctrl-e

---
 src/plugins/fakevim/fakevimhandler.cpp | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp
index 403c2856e70..37a316e037a 100644
--- a/src/plugins/fakevim/fakevimhandler.cpp
+++ b/src/plugins/fakevim/fakevimhandler.cpp
@@ -250,6 +250,8 @@ private:
     int cursorColumnInDocument() const;
     int linesInDocument() const;
     void scrollToLineInDocument(int line);
+    void scrollUp(int count);
+    void scrollDown(int count) { scrollUp(-count); }
 
     // helper functions for indenting
     bool isElectricCharacter(QChar c) const
@@ -531,7 +533,7 @@ EventResult FakeVimHandler::Private::handleEvent(QKeyEvent *ev)
         moveLeft();
 
     EDITOR(setTextCursor(m_tc));
-    EDITOR(ensureCursorVisible());
+    //EDITOR(ensureCursorVisible());
     return result;
 }
 
@@ -856,21 +858,21 @@ EventResult FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
         if (key == Key_Return || key == 't') { // cursor line to top of window
             if (!m_mvcount.isEmpty())
                 setPosition(firstPositionInLine(count()));
-            scrollToLineInDocument(cursorLineInDocument());
+            scrollUp(- cursorLineOnScreen());
             if (key == Key_Return)
                 moveToFirstNonBlankOnLine();
             finishMovement();
         } else if (key == '.' || key == 'z') { // cursor line to center of window
             if (!m_mvcount.isEmpty())
                 setPosition(firstPositionInLine(count()));
-            scrollToLineInDocument(cursorLineInDocument() - linesOnScreen() / 2);
+            scrollUp(linesOnScreen() / 2 - cursorLineOnScreen());
             if (key == '.')
                 moveToFirstNonBlankOnLine();
             finishMovement();
         } else if (key == '-' || key == 'b') { // cursor line to bottom of window
             if (!m_mvcount.isEmpty())
                 setPosition(firstPositionInLine(count()));
-            scrollToLineInDocument(cursorLineInDocument() - linesOnScreen() - 1);
+            scrollUp(linesOnScreen() - cursorLineOnScreen());
             if (key == '-')
                 moveToFirstNonBlankOnLine();
             finishMovement();
@@ -1110,6 +1112,12 @@ EventResult FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
         m_moveType = MoveInclusive;
         moveToWordBoundary(true, true);
         finishMovement();
+    } else if (key == control('e')) {
+        // FIXME: this should use the "scroll" option, and "count"
+        if (cursorLineOnScreen() == 0)
+            moveDown(1);
+        scrollDown(1);
+        finishMovement();
     } else if (key == 'f') {
         m_subsubmode = FtSubSubMode;
         m_moveType = MoveInclusive;
@@ -2154,9 +2162,15 @@ void FakeVimHandler::Private::scrollToLineInDocument(int line)
 {
     // FIXME: works only for QPlainTextEdit
     QScrollBar *scrollBar = EDITOR(verticalScrollBar());
+    //qDebug() << "SCROLL: " << scrollBar->value() << line;
     scrollBar->setValue(line);
 }
 
+void FakeVimHandler::Private::scrollUp(int count)
+{
+    scrollToLineInDocument(cursorLineInDocument() - cursorLineOnScreen() - count);
+}
+
 int FakeVimHandler::Private::lastPositionInDocument() const
 {
     QTextBlock block = m_tc.block().document()->lastBlock();
-- 
GitLab