From dee53b364560b2339551a9082c4b4a8ddcbcb17d Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Tue, 22 Nov 2022 07:56:51 -0600 Subject: [PATCH] app: fix Windows IME caret positioning Some IME editors don't send explicit GCS_CURSORPOS messages, in which case we should assume the cursor moves to the end of the composition string. Fixes: https://todo.sr.ht/~eliasnaur/gio/458 Signed-off-by: Elias Naur --- app/os_windows.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/os_windows.go b/app/os_windows.go index 21a6ab4e..0a44fdd0 100644 --- a/app/os_windows.go +++ b/app/os_windows.go @@ -407,11 +407,12 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr comp.Start = state.RunesIndex(state.UTF16Index(comp.Start) + start) } w.w.SetComposingRegion(comp) + pos := end if lParam&windows.GCS_CURSORPOS != 0 { rel := windows.ImmGetCompositionValue(imc, windows.GCS_CURSORPOS) - pos := state.RunesIndex(state.UTF16Index(rng.Start) + rel) - w.w.SetEditorSelection(key.Range{Start: pos, End: pos}) + pos = state.RunesIndex(state.UTF16Index(rng.Start) + rel) } + w.w.SetEditorSelection(key.Range{Start: pos, End: pos}) return windows.TRUE case windows.WM_IME_ENDCOMPOSITION: w.w.SetComposingRegion(key.Range{Start: -1, End: -1})