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

This commit is contained in:
Le Tan 2017-07-20 19:20:04 +08:00
parent 8a6ce16db5
commit 365c0ce91f
2 changed files with 32 additions and 1 deletions

View File

@ -7,6 +7,8 @@
#include <QFontMetrics> #include <QFontMetrics>
#include <QFont> #include <QFont>
#include <QHeaderView> #include <QHeaderView>
#include <QInputMethod>
#include <QGuiApplication>
#include "vconfigmanager.h" #include "vconfigmanager.h"
#include "vbuttonwithwidget.h" #include "vbuttonwithwidget.h"
@ -332,7 +334,7 @@ void VVimIndicator::triggerCommandLine(VVim::CommandLineType p_type)
VVimCmdLineEdit::VVimCmdLineEdit(QWidget *p_parent) VVimCmdLineEdit::VVimCmdLineEdit(QWidget *p_parent)
: QLineEdit(p_parent), m_type(VVim::CommandLineType::Invalid), : 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. // When user delete all the text, cancel command input.
connect(this, &VVimCmdLineEdit::textChanged, connect(this, &VVimCmdLineEdit::textChanged,
@ -401,6 +403,28 @@ void VVimCmdLineEdit::reset(VVim::CommandLineType p_type)
setCommand(""); setCommand("");
show(); show();
setFocus(); 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. // See if @p_modifiers is Control which is different on macOs and Windows.

View File

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