app crashed after ImeOnDocumentFeed() called for window mode IME, see https://github.com/zufuliu/notepad2/issues/775 .
I feel this due to wrong information returned to IME:
for window mode IME, std::wstring rcFeed doesn't contains current composition string, so dwCompStrLen (larger than rcFeed.length()) and dwCompStrOffset are invalid.
for typing # then i:
// inline mode
rcFeedLen=6, compStrLen=2, imeCaretPos=2, curPos=3, compStart=1, compStrOffset=1
// window mode
rcFeedLen=2, compStrLen=2, imeCaretPos=2, curPos=1, compStart=-1, compStrOffset=0
Set
dwCompStrLenanddwCompStrOffsetto zero indeed "fixed" the crash.Diff:
compStrLencomes fromGCS_COMPSTR, so what is the text ofGCS_COMPSTRand how does it relate to the document?GCS_COMPSTRischafter typingi, for window mode,rcFeedis#, inline modercFeedis#ch.So it needs to detect windowed IME (unsure if
imeInteractionis sufficient) and setcompStartandcompStrOffsetto 0 when windowed.Just got three ideas to fix this:
1. disable
ImeOnDocumentFeed()for window mode IME.2. set
compStartandcompStrOffsetto 0 whenrcFeednot contains currentGCS_COMPSTR.3. insert current
GCS_COMPSTRintorcFeedat caret position when it not contains the former.The text around the caret may still be useful for the contextual choice of composition, even in windowed mode so (1) seems poor. (2) seems reasonable to me. The IME knows what the composition string is so shouldn't need (3) and may be confused by it.
Its likely only the main caret-based string (
dwStrLen,dwStrOffset) that is useful for context.Patch to fix the crash (only need to set
compStrLento 0 for window mode).compStrOffsetfor window mode is changed to compute fromcurPosinstead of the wronglyimeCaretPosoffset.imc.GetCompositionString(GCS_COMPSTR).size()is replaced with a new functionimc.GetCompositionStringLength(GCS_COMPSTR)to eliminate the temporary string.The Patch.
Diff:
Committed as [e8da1f].
Related
Commit: [e8da1f]