commit 0a1483bc9e6480ed1827b3b7f13d3c1f818a9d8d
Author: Koji Yokota <[email protected]>
Date: Wed Jun 25 12:37:47 2025 +0900
Selectively allow preedit to go into math mode
---
src/frontends/qt/GuiApplication.cpp | 2 +-
src/frontends/qt/GuiInputMethod.cpp | 21 +++++++++++++++++++--
src/frontends/qt/GuiInputMethod.h | 1 +
src/frontends/qt/GuiWorkArea.cpp | 4 +++-
4 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/src/frontends/qt/GuiApplication.cpp
b/src/frontends/qt/GuiApplication.cpp
index ba53be0718..c1f972ebc3 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -2365,7 +2365,7 @@ string GuiApplication::inputLanguageCode() const
void GuiApplication::onLocaleChanged()
{
- //LYXERR0("Change language to " << inputLanguage()->lang());
+ //LYXERR0("Change language to " << inputLanguageCode());
if (currentView() && currentView()->currentBufferView())
currentView()->currentBufferView()->cursor().setLanguageFromInput();
}
diff --git a/src/frontends/qt/GuiInputMethod.cpp
b/src/frontends/qt/GuiInputMethod.cpp
index 2d2a57cf37..0eff28c3be 100644
--- a/src/frontends/qt/GuiInputMethod.cpp
+++ b/src/frontends/qt/GuiInputMethod.cpp
@@ -54,6 +54,9 @@ struct GuiInputMethod::Private
QInputMethod * sys_im_ = guiApp->inputMethod();
QLocale locale_;
+ /// if language should not use preedit in the math mode
+ bool preedit_not_in_math_ = false;
+
ColorCache & color_cache_ = guiApp->colorCache();
QColor font_color_;
QBrush font_brush_;
@@ -99,6 +102,8 @@ GuiInputMethod::GuiInputMethod(GuiWorkArea *parent)
this, &GuiInputMethod::toggleInputMethodAcceptance);
connect(this, &GuiInputMethod::inputMethodStateChanged,
d->sys_im_, &QInputMethod::update);
+ connect(d->sys_im_, &QInputMethod::localeChanged,
+ this, &GuiInputMethod::onLocaleChanged);
}
GuiInputMethod::~GuiInputMethod()
@@ -109,8 +114,9 @@ GuiInputMethod::~GuiInputMethod()
void GuiInputMethod::toggleInputMethodAcceptance(){
// note that d->cur_->inset() is a cache so it lags from actual key
moves
- if (d->cur_->inset().currentMode() == Inset::MATH_MODE ||
- guiApp->isInCommandMode())
+ if (d->preedit_not_in_math_ &&
+ (d->cur_->inset().currentMode() == Inset::MATH_MODE ||
+ guiApp->isInCommandMode()))
d->im_state_.enabled_ = false;
else
d->im_state_.enabled_ = true;
@@ -119,6 +125,17 @@ void GuiInputMethod::toggleInputMethodAcceptance(){
}
+void GuiInputMethod::onLocaleChanged()
+{
+ QLocale lang = d->sys_im_->locale().language();
+ if (lang == QLocale::Chinese || lang == QLocale::Japanese ||
+ lang == QLocale::Korean)
+ d->preedit_not_in_math_ = true;
+ else
+ d->preedit_not_in_math_ = false;
+}
+
+
#ifdef Q_DEBUG
// this is experimental (2024/10/28)
// don't input methods implement ImHints except for Qt::ImhDigitsOnly yet?
diff --git a/src/frontends/qt/GuiInputMethod.h
b/src/frontends/qt/GuiInputMethod.h
index 87c00c6efe..684088a37d 100644
--- a/src/frontends/qt/GuiInputMethod.h
+++ b/src/frontends/qt/GuiInputMethod.h
@@ -126,6 +126,7 @@ public Q_SLOT:
void processQuery(Qt::InputMethodQuery query);
/// Turn off IM in math mode and command phase and turn it on otherwise
void toggleInputMethodAcceptance() override;
+ void onLocaleChanged();
#ifdef Q_DEBUG
///
void setHint(InputMethod::Hint hint) override;
diff --git a/src/frontends/qt/GuiWorkArea.cpp b/src/frontends/qt/GuiWorkArea.cpp
index e7ac91449e..22d0971b82 100644
--- a/src/frontends/qt/GuiWorkArea.cpp
+++ b/src/frontends/qt/GuiWorkArea.cpp
@@ -1340,7 +1340,9 @@ void GuiWorkArea::paintEvent(QPaintEvent * ev)
void GuiWorkArea::inputMethodEvent(QInputMethodEvent * ev)
{
- Q_EMIT preeditChanged(ev);
+ // LYXERR0("preeditString: " << ev->preeditString()
+ // << " commitString: " << ev->commitString());
+ Q_EMIT preeditChanged(ev);
}
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs