From d853508df8c3d391ff841aa9ad65670b4e163422 Mon Sep 17 00:00:00 2001 From: Zufu Liu Date: Fri, 22 Mar 2024 15:28:29 +1100 Subject: Bug [#2433]. Fix IME crash in windowed mode. --- doc/ScintillaHistory.html | 6 +++++- win32/ScintillaWin.cxx | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 9ec26d44c..331a76420 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -584,7 +584,7 @@

Releases

- Release 5.4.4 + Release 5.5.0

Release 5.4.3 diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 806d915b7..c6733469c 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -277,6 +277,11 @@ public: return attr; } + LONG GetCompositionStringLength(DWORD dwIndex) const noexcept { + const LONG byteLen = ::ImmGetCompositionStringW(hIMC, dwIndex, nullptr, 0); + return byteLen / sizeof(wchar_t); + } + std::wstring GetCompositionString(DWORD dwIndex) { const LONG byteLen = ::ImmGetCompositionStringW(hIMC, dwIndex, nullptr, 0); std::wstring wcs(byteLen / 2, 0); @@ -3184,9 +3189,14 @@ LRESULT ScintillaWin::ImeOnDocumentFeed(LPARAM lParam) const { if (!imc.hIMC) return 0; - const size_t compStrLen = imc.GetCompositionString(GCS_COMPSTR).size(); - const int imeCaretPos = imc.GetImeCaretPos(); - const Sci::Position compStart = pdoc->GetRelativePositionUTF16(curPos, -imeCaretPos); + DWORD compStrLen = 0; + Sci::Position compStart = curPos; + if (pdoc->TentativeActive()) { + // rcFeed contains current composition string + compStrLen = imc.GetCompositionStringLength(GCS_COMPSTR); + const int imeCaretPos = imc.GetImeCaretPos(); + compStart = pdoc->GetRelativePositionUTF16(curPos, -imeCaretPos); + } const Sci::Position compStrOffset = pdoc->CountUTF16(lineStart, compStart); // Fill in reconvert structure. @@ -3194,7 +3204,7 @@ LRESULT ScintillaWin::ImeOnDocumentFeed(LPARAM lParam) const { rc->dwVersion = 0; //constant rc->dwStrLen = static_cast(rcFeed.length()); rc->dwStrOffset = sizeof(RECONVERTSTRING); //constant - rc->dwCompStrLen = static_cast(compStrLen); + rc->dwCompStrLen = compStrLen; rc->dwCompStrOffset = static_cast(compStrOffset) * sizeof(wchar_t); rc->dwTargetStrLen = rc->dwCompStrLen; rc->dwTargetStrOffset = rc->dwCompStrOffset; -- cgit v1.2.3