From 038bf711fae3305a57467392ae2c281caa15bbb9 Mon Sep 17 00:00:00 2001 From: Tuomas Siipola Date: Tue, 16 Jul 2019 10:12:52 +0000 Subject: [PATCH] Fix text input cursor position with non-ASCII text Fixes #171 --- lib/ui/textinput.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go index a3127e5..2feeb84 100644 --- a/lib/ui/textinput.go +++ b/lib/ui/textinput.go @@ -73,16 +73,16 @@ func (ti *TextInput) Draw(ctx *Context) { ti.ctx = ctx // gross ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault) - text := string(ti.text[scroll:]) + text := ti.text[scroll:] sindex := ti.index - scroll if ti.password { x := ctx.Printf(0, 0, tcell.StyleDefault, "%s", ti.prompt) cells := runewidth.StringWidth(string(text)) ctx.Fill(x, 0, cells, 1, '*', tcell.StyleDefault) } else { - ctx.Printf(0, 0, tcell.StyleDefault, "%s%s", ti.prompt, text) + ctx.Printf(0, 0, tcell.StyleDefault, "%s%s", ti.prompt, string(text)) } - cells := runewidth.StringWidth(text[:sindex] + ti.prompt) + cells := runewidth.StringWidth(string(text[:sindex]) + ti.prompt) if ti.focus { ctx.SetCursor(cells, 0) }