From 2dc19a36959c6e4a5e99a13e6ade83eeb5b3d164 Mon Sep 17 00:00:00 2001 From: tainted-bit Date: Fri, 12 Jun 2020 17:13:57 +0200 Subject: [PATCH] widget: use byte length when comparing with caret position Fixes misaligned carets when the Editor text contains code points represented by multiple UTF-8 bytes. Line lengths should be measured in bytes instead of glyphs for caret positioning. Signed-off-by: tainted-bit --- widget/editor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widget/editor.go b/widget/editor.go index 91ac6eea..2c1b4142 100644 --- a/widget/editor.go +++ b/widget/editor.go @@ -483,7 +483,7 @@ loop: l := e.lines[carLine] y += (prevDesc + l.Ascent).Ceil() prevDesc = l.Descent - if carLine == len(e.lines)-1 || idx+len(l.Layout) > e.rr.caret { + if carLine == len(e.lines)-1 || idx+l.Len > e.rr.caret { for _, g := range l.Layout { if idx == e.rr.caret { break loop