app: [macOS] fix caret position calculation after IME text insert

Fixes: https://todo.sr.ht/~eliasnaur/gio/385
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-04-08 13:05:27 +02:00
parent 4e488f4c70
commit 49bd5787e4
+5 -1
View File
@@ -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})
}