[LyX/master] Fix ticket #13345 (#3)

Koji Yokota <[email protected]> Tue, 07 Jul 2026 00:06:33 +0000
Newsgroups gmane.editors.lyx.cvs
Message-ID <[email protected]>
commit b6c5fe401d3e3d838a8583b0058759886ff71125
Author: Koji Yokota <[email protected]>
Date:   Tue Jul 7 08:57:12 2026 +0900

    Fix ticket #13345 (#3)
    
    Many thanks to JMarc and Jürgen
---
 src/frontends/qt/GuiInputMethod.cpp | 20 ++++++--------------
 src/frontends/qt/GuiInputMethod.h   |  6 ++++++
 2 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/src/frontends/qt/GuiInputMethod.cpp b/src/frontends/qt/GuiInputMethod.cpp
index 8d08821856..0ef7e9b342 100644
--- a/src/frontends/qt/GuiInputMethod.cpp
+++ b/src/frontends/qt/GuiInputMethod.cpp
@@ -607,7 +607,7 @@ pos_type GuiInputMethod::setTextFormat(const QInputMethodEvent::Attribute & it,
 pos_type GuiInputMethod::pickNextSegFromTurnout(pos_type next_seg_pos, size_type length,
                                                 QTextCharFormat * cf)
 {
-	std::vector<PreeditSegment> to_erase;
+	auto to_erase = d->seg_turnout_.end();
 	std::vector<PreeditSegment> carryover;
 	bool is_matched = false;
 
@@ -717,7 +717,7 @@ pos_type GuiInputMethod::pickNextSegFromTurnout(pos_type next_seg_pos, size_type
 
 			next_seg_pos += length;
 			if (d->seg_turnout_.size() > 1)
-				to_erase.push_back(*past_attr);
+				to_erase = past_attr;
 			is_matched = true;
 			break; // assuming no duplicates in seg_turnout_
 		}
@@ -731,18 +731,10 @@ pos_type GuiInputMethod::pickNextSegFromTurnout(pos_type next_seg_pos, size_type
 			        << d->seg_turnout_.back().start_
 			               + d->seg_turnout_.back().length_ << ")");
 			d->seg_turnout_.pop_back();
-		} else if (d->seg_turnout_.size() > 1) {
-			for (auto it = to_erase.begin(); it != to_erase.end(); it++) {
-				LYXERR(Debug::KEY, "Removing from preedit turnout: ["
-				        << it->start_ << ", "
-				        << it->start_ + it->length_ << ")");
-				for (auto it2 = d->seg_turnout_.begin();
-				     it2 != d->seg_turnout_.end();)
-					if (*it == *it2)
-						d->seg_turnout_.erase(it2);
-					else
-						++it2;
-			}
+		} else if (to_erase != d->seg_turnout_.end()) {
+			LYXERR(Debug::KEY, "Removing from preedit turnout: [" <<
+				   to_erase->start_ << ", " << to_erase->start_ + to_erase->length_ << ")");
+			d->seg_turnout_.erase(to_erase);
 		}
 	}
 	// Append the remainder to d->seg_turnout_
diff --git a/src/frontends/qt/GuiInputMethod.h b/src/frontends/qt/GuiInputMethod.h
index 36b129f63f..c8ce0a873b 100644
--- a/src/frontends/qt/GuiInputMethod.h
+++ b/src/frontends/qt/GuiInputMethod.h
@@ -52,6 +52,12 @@ public:
 			return start_ == another.start_ && length_ == another.length_ &&
 			        char_format_ == another.char_format_;
 		}
+		PreeditSegment & operator=(const PreeditSegment & another) {
+			start_ = another.start_;
+			length_ = another.length_;
+			char_format_ = another.char_format_;
+			return *this;
+		}
 	};
 
 	struct PreeditStyle {
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs