From 1e46b6232b460ecf04cc1280179b9e0bc8bccfbf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Aum=C3=BCller?= <aumuell@reserv.at>
Date: Tue, 5 Jan 2010 15:30:22 +0100
Subject: [PATCH] fakevim: leave shortcut-passing mode after one shortcut has
 been pressed

this behaviour seems more natural to me, but it has one draw-back: if an
action associated to a shortcut is not enabled, typing that shortcut won't
leave passing mode
---
 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 a85c6031e39..9ec88387d39 100755
--- a/src/plugins/fakevim/fakevimhandler.cpp
+++ b/src/plugins/fakevim/fakevimhandler.cpp
@@ -281,6 +281,7 @@ public:
     void fixMarks(int positionAction, int positionChange); //Updates marks positions by the difference in positionChange
 
     void installEventFilter();
+    void passShortcuts(bool enable);
     void setupWidget();
     void restoreWidget();
 
@@ -611,6 +612,7 @@ EventResult FakeVimHandler::Private::handleEvent(QKeyEvent *ev)
     }
 
     if (m_passing) {
+        passShortcuts(false);
         KEY_DEBUG("PASSING PLAIN KEY..." << ev->key() << ev->text());
         //if (key == ',') { // use ',,' to leave, too.
         //    qDebug() << "FINISHED...";
@@ -1104,6 +1106,16 @@ void FakeVimHandler::Private::notImplementedYet()
     updateMiniBuffer();
 }
 
+void FakeVimHandler::Private::passShortcuts(bool enable)
+{
+    m_passing = enable;
+    updateMiniBuffer();
+    if (enable)
+        QCoreApplication::instance()->installEventFilter(q);
+    else
+        QCoreApplication::instance()->removeEventFilter(q);
+}
+
 EventResult FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
     const QString &text)
 {
@@ -1346,10 +1358,7 @@ EventResult FakeVimHandler::Private::handleCommandMode(int key, int unmodified,
             m_visualTargetColumn = -1;
         finishMovement("%1$", count());
     } else if (key == ',') {
-        // FIXME: use some other mechanism
-        //m_passing = true;
-        m_passing = !m_passing;
-        updateMiniBuffer();
+        passShortcuts(true);
     } else if (key == '.') {
         //qDebug() << "REPEATING" << quoteUnprintable(m_dotCommand) << count();
         QString savedCommand = m_dotCommand;
@@ -3421,6 +3430,11 @@ bool FakeVimHandler::eventFilter(QObject *ob, QEvent *ev)
 {
     bool active = theFakeVimSetting(ConfigUseFakeVim)->value().toBool();
 
+    if (active && ev->type() == QEvent::Shortcut) {
+        d->passShortcuts(false);
+        return false;
+    }
+
     if (active && ev->type() == QEvent::KeyPress && ob == d->editor()) {
         QKeyEvent *kev = static_cast<QKeyEvent *>(ev);
         KEY_DEBUG("KEYPRESS" << kev->key());
-- 
GitLab