Fix text input cursor position with non-ASCII text

Fixes #171
This commit is contained in:
Tuomas Siipola 2019-07-16 10:12:52 +00:00 committed by Drew DeVault
parent d43684cd90
commit 038bf711fa
1 changed files with 3 additions and 3 deletions

View File

@ -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)
}