lib/ui/textinput: Optimize ensureScroll

This commit is contained in:
Adnan Maolood 2021-08-24 10:41:39 -04:00 committed by Drew DeVault
parent d39c6b449e
commit 0b19b5e70e

View file

@ -167,12 +167,12 @@ func (ti *TextInput) ensureScroll() {
if ti.ctx == nil { if ti.ctx == nil {
return return
} }
// God why am I this lazy w := ti.ctx.Width() - len(ti.prompt)
for ti.index-ti.scroll >= ti.ctx.Width() { if ti.index >= ti.scroll+w {
ti.scroll++ ti.scroll = ti.index - w + 1
} }
for ti.index-ti.scroll < 0 { if ti.index < ti.scroll {
ti.scroll-- ti.scroll = ti.index
} }
} }