aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjohnsonj <unknown>2023-06-18 19:29:14 +1000
committerjohnsonj <unknown>2023-06-18 19:29:14 +1000
commit5ad83ff87df54c085be87cde61215b3ee32a2e1a (patch)
tree74b4963ead1dd589090c9ee717f981982b1605c2
parentdec3e9e7991c51374846f1be80c81fde3412836c (diff)
downloadscintilla-mirror-5ad83ff87df54c085be87cde61215b3ee32a2e1a.tar.gz
Implement replacement for IMEs which may help with actions like reconversion.
-rw-r--r--doc/ScintillaHistory.html4
-rw-r--r--qt/ScintillaEditBase/ScintillaEditBase.cpp11
2 files changed, 15 insertions, 0 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index e84d43cb0..f60eb3933 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -601,6 +601,10 @@
On Qt, for IMEs, update micro focus when selection changes.
This may move the location of IME popups to align with the caret.
</li>
+ <li>
+ On Qt, implement replacement for IMEs which may help with actions like reconversion.
+ This is similar to delete-surrounding on GTK.
+ </li>
</ul>
<h3>
<a href="https://www.scintilla.org/scintilla535.zip">Release 5.3.5</a>
diff --git a/qt/ScintillaEditBase/ScintillaEditBase.cpp b/qt/ScintillaEditBase/ScintillaEditBase.cpp
index b64070407..5072cd824 100644
--- a/qt/ScintillaEditBase/ScintillaEditBase.cpp
+++ b/qt/ScintillaEditBase/ScintillaEditBase.cpp
@@ -542,6 +542,17 @@ void ScintillaEditBase::inputMethodEvent(QInputMethodEvent *event)
sqt->view.imeCaretBlockOverride = false;
preeditPos = -1; // reset not to interrupt Qt::ImCursorRectangle.
+ const int rpLength = event->replacementLength();
+ if (rpLength != 0) {
+ // Qt has called setCommitString().
+ // Make room for the string to sit in.
+ const int rpStart = event->replacementStart();
+ const Scintilla::Position rpBase = sqt->CurrentPosition();
+ const Scintilla::Position start = sqt->pdoc->GetRelativePositionUTF16(rpBase, rpStart);
+ const Scintilla::Position end = sqt->pdoc->GetRelativePositionUTF16(start, rpLength);
+ sqt->pdoc->DeleteChars(start, end - start);
+ }
+
if (!event->commitString().isEmpty()) {
const QString &commitStr = event->commitString();
const int commitStrLen = commitStr.length();