From 49bd5787e4c9c53c417cf39b061cedfa4c03ee79 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 8 Apr 2022 13:05:27 +0200 Subject: [PATCH] app: [macOS] fix caret position calculation after IME text insert Fixes: https://todo.sr.ht/~eliasnaur/gio/385 Signed-off-by: Elias Naur --- app/os_macos.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/os_macos.go b/app/os_macos.go index e87116cc..5854b6ad 100644 --- a/app/os_macos.go +++ b/app/os_macos.go @@ -636,7 +636,11 @@ func gio_insertText(view, cstr C.CFTypeRef, crng C.NSRange) { str := nsstringToString(cstr) w.w.EditorReplace(rng, str) w.w.SetComposingRegion(key.Range{Start: -1, End: -1}) - pos := rng.Start + utf8.RuneCountInString(str) + start := rng.Start + if rng.End < start { + start = rng.End + } + pos := start + utf8.RuneCountInString(str) w.w.SetEditorSelection(key.Range{Start: pos, End: pos}) }