Browse Source

vim-mode: disable input method in Command type in command line edit

Le Tan 8 years ago
parent
commit
365c0ce91f
2 changed files with 32 additions and 1 deletions
  1. 25 1
      src/vvimindicator.cpp
  2. 7 0
      src/vvimindicator.h

+ 25 - 1
src/vvimindicator.cpp

@@ -7,6 +7,8 @@
 #include <QFontMetrics>
 #include <QFont>
 #include <QHeaderView>
+#include <QInputMethod>
+#include <QGuiApplication>
 
 #include "vconfigmanager.h"
 #include "vbuttonwithwidget.h"
@@ -332,7 +334,7 @@ void VVimIndicator::triggerCommandLine(VVim::CommandLineType p_type)
 
 VVimCmdLineEdit::VVimCmdLineEdit(QWidget *p_parent)
     : QLineEdit(p_parent), m_type(VVim::CommandLineType::Invalid),
-      m_registerPending(false)
+      m_registerPending(false), m_enableInputMethod(true)
 {
     // When user delete all the text, cancel command input.
     connect(this, &VVimCmdLineEdit::textChanged,
@@ -401,6 +403,28 @@ void VVimCmdLineEdit::reset(VVim::CommandLineType p_type)
     setCommand("");
     show();
     setFocus();
+    setInputMethodEnabled(p_type != VVim::CommandLineType::Command);
+}
+
+void VVimCmdLineEdit::setInputMethodEnabled(bool p_enabled)
+{
+    if (m_enableInputMethod != p_enabled) {
+        m_enableInputMethod = p_enabled;
+
+        QInputMethod *im = QGuiApplication::inputMethod();
+        im->reset();
+        // Ask input method to query current state, which will call inputMethodQuery().
+        im->update(Qt::ImEnabled);
+    }
+}
+
+QVariant VVimCmdLineEdit::inputMethodQuery(Qt::InputMethodQuery p_query) const
+{
+    if (p_query == Qt::ImEnabled) {
+        return m_enableInputMethod;
+    }
+
+    return QLineEdit::inputMethodQuery(p_query);
 }
 
 // See if @p_modifiers is Control which is different on macOs and Windows.

+ 7 - 0
src/vvimindicator.h

@@ -29,6 +29,8 @@ public:
 
     void restoreUserLastInput();
 
+    QVariant inputMethodQuery(Qt::InputMethodQuery p_query) const Q_DECL_OVERRIDE;
+
 signals:
     // User has finished the input and the command is ready to execute.
     void commandFinished(VVim::CommandLineType p_type, const QString &p_cmd);
@@ -59,6 +61,8 @@ private:
 
     void setRegisterPending(bool p_pending);
 
+    void setInputMethodEnabled(bool p_enabled);
+
     VVim::CommandLineType m_type;
 
     // The latest command user input.
@@ -68,6 +72,9 @@ private:
     bool m_registerPending;
 
     QString m_originStyleSheet;
+
+    // Whether enable input method.
+    bool m_enableInputMethod;
 };
 
 class VVimIndicator : public QWidget