[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [ktexteditor] src/vimode: *sigh* - in Input mode, Qt seems to send each keypress first as a Shortcut
From:       Simon St James <kdedevel () etotheipiplusone ! com>
Date:       2016-06-18 8:35:36
Message-ID: E1bEBj6-0002HX-7Y () code ! kde ! org
[Download RAW message or body]

Git commit 88fc845ecd94e023d75d72c6152f2af04a702a51 by Simon St James.
Committed on 18/06/2016 at 08:35.
Pushed by sstjames into branch 'master'.

*sigh* - in Input mode, Qt seems to send each keypress first as a ShortcutOverride \
(even if it doesn't override any shortcuts!) and then as a KeyPress (whether or not \
we stole the "ShortcutOverride" or not!), so the MacroRecorder (and \
LastChangeRecorder) record each keypress twice, leading to them repeating each \
keypress when replayed.  Introduce isRepeatOfShortcutOverrideAsKeyPress() to detect \
this and not store both events.

M  +17   -0    src/vimode/lastchangerecorder.cpp
M  +7    -0    src/vimode/lastchangerecorder.h
M  +3    -0    src/vimode/macrorecorder.cpp

http://commits.kde.org/ktexteditor/88fc845ecd94e023d75d72c6152f2af04a702a51

diff --git a/src/vimode/lastchangerecorder.cpp b/src/vimode/lastchangerecorder.cpp
index 77fe24c..ff44f63 100644
--- a/src/vimode/lastchangerecorder.cpp
+++ b/src/vimode/lastchangerecorder.cpp
@@ -25,6 +25,20 @@
 
 using namespace KateVi;
 
+bool KateVi::isRepeatOfLastShortcutOverrideAsKeyPress(const QKeyEvent& \
currentKeyPress, const QList<QKeyEvent>& keyEventLog) +{
+    if (keyEventLog.empty())
+        return false;
+    const QKeyEvent& lastKeyPress = keyEventLog.last();
+    if (lastKeyPress.type() == QEvent::ShortcutOverride && currentKeyPress.type() == \
QEvent::KeyPress && +        lastKeyPress.key() == currentKeyPress.key() &&
+        lastKeyPress.modifiers() == currentKeyPress.modifiers())
+    {
+        return true;
+    }
+    return false;
+}
+
 LastChangeRecorder::LastChangeRecorder(InputModeManager *viInputModeManager)
     : m_viInputModeManager(viInputModeManager)
     , m_isReplaying(false)
@@ -37,6 +51,9 @@ LastChangeRecorder::~LastChangeRecorder()
 
 void LastChangeRecorder::record(const QKeyEvent &e)
 {
+    if (isRepeatOfLastShortcutOverrideAsKeyPress(e, m_changeLog))
+        return;
+
     if (e.key() != Qt::Key_Shift && e.key() != Qt::Key_Control && e.key() != \
Qt::Key_Meta && e.key() != Qt::Key_Alt) {  m_changeLog.append(e);
     }
diff --git a/src/vimode/lastchangerecorder.h b/src/vimode/lastchangerecorder.h
index 2cfdf33..4a9efff 100644
--- a/src/vimode/lastchangerecorder.h
+++ b/src/vimode/lastchangerecorder.h
@@ -31,6 +31,13 @@ namespace KateVi
 {
 class InputModeManager;
 
+/**
+ * In e.g. Insert mode, Qt seems to feed each keypress through twice; once as a \
ShortcutOverride (even if the key + * doesn't actually appear to be a \
ShortcutOverride) and then, whether the "ShortcutOverride" was accepted or not, + * \
again as a KeyPress.  We don't want to store both, so this helper helps to decide \
what to do. + */
+bool isRepeatOfLastShortcutOverrideAsKeyPress(const QKeyEvent& currentKeyPress, \
const QList<QKeyEvent>& keyEventLog); +
 class LastChangeRecorder
 {
 public:
diff --git a/src/vimode/macrorecorder.cpp b/src/vimode/macrorecorder.cpp
index 24e5487..9a8d6c1 100644
--- a/src/vimode/macrorecorder.cpp
+++ b/src/vimode/macrorecorder.cpp
@@ -26,6 +26,7 @@
 #include "globalstate.h"
 #include "macros.h"
 #include "completionreplayer.h"
+#include "lastchangerecorder.h"
 
 namespace {
     const QChar LastPlayedRegister = QLatin1Char('@');
@@ -70,6 +71,8 @@ bool MacroRecorder::isRecording() const
 
 void MacroRecorder::record(const QKeyEvent &event)
 {
+    if (isRepeatOfLastShortcutOverrideAsKeyPress(event, m_eventsLog))
+        return;
     m_eventsLog.append(event);
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic