[LyX/master] Add a safegurard for GuiInputMethod::setCaretRectangle()
Koji Yokota
yokota at lyx.org
Thu Jun 25 00:59:27 UTC 2026
commit 7f132ea40c8f1b5534974131614ea1556166e6ce
Author: Koji Yokota <yokota at lyx.org>
Date: Wed Jun 24 08:51:28 2026 +0900
Add a safegurard for GuiInputMethod::setCaretRectangle()
When IM is turned on after entering the math mode, inconsistency between
this function and clearCaretRectangle() can happen.
---
src/frontends/InputMethod.h | 3 +++
src/frontends/qt/GuiInputMethod.cpp | 5 +++++
src/frontends/qt/GuiInputMethod.h | 1 +
src/frontends/qt/GuiWorkArea.cpp | 3 ++-
4 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/frontends/InputMethod.h b/src/frontends/InputMethod.h
index bb4a56da63..cd5e1845a0 100644
--- a/src/frontends/InputMethod.h
+++ b/src/frontends/InputMethod.h
@@ -14,6 +14,7 @@
#include "support/docstring.h"
#include "support/types.h"
+#include <vector>
namespace lyx {
@@ -87,6 +88,8 @@ public:
virtual void setElemsCoordinates(int x, int y) = 0;
///
virtual void clearElemsCoordinates() = 0;
+ ///
+ virtual std::vector<std::array<int,2>> elemsCoordinates() = 0;
#ifdef Q_DEBUG
///
virtual void setHint(Hint) = 0;
diff --git a/src/frontends/qt/GuiInputMethod.cpp b/src/frontends/qt/GuiInputMethod.cpp
index e2f40946b8..79fea2e7ae 100644
--- a/src/frontends/qt/GuiInputMethod.cpp
+++ b/src/frontends/qt/GuiInputMethod.cpp
@@ -891,6 +891,11 @@ void GuiInputMethod::setElemsCoordinates(int x, int y)
d->elems_coords_.push_back({x,y});
}
+std::vector<std::array<int, 2> > GuiInputMethod::elemsCoordinates()
+{
+ return d->elems_coords_;
+}
+
void GuiInputMethod::clearElemsCoordinates()
{
diff --git a/src/frontends/qt/GuiInputMethod.h b/src/frontends/qt/GuiInputMethod.h
index e843701170..8c02673af4 100644
--- a/src/frontends/qt/GuiInputMethod.h
+++ b/src/frontends/qt/GuiInputMethod.h
@@ -123,6 +123,7 @@ public:
/// Whether the segment contains language that allows wrapping anywhere
bool canWrapAnywhere(pos_type const) override;
void setElemsCoordinates(int x, int y) override;
+ std::vector<std::array<int,2>> elemsCoordinates() override;
void clearElemsCoordinates() override;
Q_SIGNALS:
void preeditProcessed(QInputMethodEvent* ev);
diff --git a/src/frontends/qt/GuiWorkArea.cpp b/src/frontends/qt/GuiWorkArea.cpp
index 5a067ef9aa..3fb3f26e79 100644
--- a/src/frontends/qt/GuiWorkArea.cpp
+++ b/src/frontends/qt/GuiWorkArea.cpp
@@ -1405,7 +1405,8 @@ void GuiWorkArea::paintEvent(QPaintEvent * ev)
d->updateCaretGeometry();
if (d->im_->preeditString().empty() && d->caret_visible_) {
d->drawCaret(pain, d->buffer_view_->horizScrollOffset());
- } else if (!d->im_->preeditString().empty()) {
+ } else if (!d->im_->preeditString().empty() &&
+ !d->im_->elemsCoordinates().empty()) {
d->im_->setCaretRectangle();
if (d->im_->isCaretVisible())
d->drawPreeditCaret(pain);
More information about the lyx-cvs
mailing list