From 365c0ce91f56d4c596321ffffc5980e28b9a436d Mon Sep 17 00:00:00 2001 From: Le Tan Date: Thu, 20 Jul 2017 19:20:04 +0800 Subject: [PATCH] vim-mode: disable input method in Command type in command line edit --- src/vvimindicator.cpp | 26 +++++++++++++++++++++++++- src/vvimindicator.h | 7 +++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/vvimindicator.cpp b/src/vvimindicator.cpp index 2289993c..8e241b47 100644 --- a/src/vvimindicator.cpp +++ b/src/vvimindicator.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #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. diff --git a/src/vvimindicator.h b/src/vvimindicator.h index 42fa1e07..74b1ea55 100644 --- a/src/vvimindicator.h +++ b/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