aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorchengzhi <unknown>2023-05-08 22:35:33 +1000
committerchengzhi <unknown>2023-05-08 22:35:33 +1000
commitc4a842244c93ac95d890b9bcc001f4174cf39b8a (patch)
treef1b9c9ca5b2041edc270b2f6b708607850e97069
parent17decc27587b4e58942ac8fe5492ee35049caf79 (diff)
downloadscintilla-mirror-c4a842244c93ac95d890b9bcc001f4174cf39b8a.tar.gz
On Qt for Cocoa, fix crash in entry of multi-character strings with IME.
https://github.com/dail8859/NotepadNext/issues/194 https://github.com/dail8859/NotepadNext/pull/372
-rw-r--r--doc/ScintillaHistory.html5
-rw-r--r--qt/ScintillaEditBase/ScintillaEditBase.cpp11
2 files changed, 14 insertions, 2 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index f0cb2ba43..d498e4e98 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -576,6 +576,8 @@
<td>Ferdinand Oeinck</td>
<td>Michael Heath</td>
<td>Enrico Tröger</td>
+ </tr><tr>
+ <td>chengzhi</td>
</tr>
</table>
<h2>Releases</h2>
@@ -595,6 +597,9 @@
by GdiAlphaBlend.
<a href="https://sourceforge.net/p/scintilla/bugs/1923/">Bug #1923</a>.
</li>
+ <li>
+ On Qt for Cocoa, fix crash in entry of multi-character strings with IME.
+ </li>
</ul>
<h3>
<a href="https://www.scintilla.org/scintilla534.zip">Release 5.3.4</a>
diff --git a/qt/ScintillaEditBase/ScintillaEditBase.cpp b/qt/ScintillaEditBase/ScintillaEditBase.cpp
index b58a118aa..f789af727 100644
--- a/qt/ScintillaEditBase/ScintillaEditBase.cpp
+++ b/qt/ScintillaEditBase/ScintillaEditBase.cpp
@@ -268,8 +268,15 @@ void ScintillaEditBase::keyPressEvent(QKeyEvent *event)
QString text = event->text();
if (input && !text.isEmpty() && text[0].isPrint()) {
- QByteArray utext = sqt->BytesForDocument(text);
- sqt->InsertCharacter(std::string_view(utext.data(), utext.size()), CharacterSource::DirectInput);
+ const int strLen = text.length();
+ for (int i = 0; i < strLen;) {
+ const int ucWidth = text.at(i).isHighSurrogate() ? 2 : 1;
+ const QString oneCharUTF16 = text.mid(i, ucWidth);
+ const QByteArray oneChar = sqt->BytesForDocument(oneCharUTF16);
+
+ sqt->InsertCharacter(std::string_view(oneChar.data(), oneChar.length()), CharacterSource::DirectInput);
+ i += ucWidth;
+ }
} else {
event->ignore();
}