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
1 changed files with 5 additions and 5 deletions

View File

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