aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdnan Maolood <me@adnano.co>2021-08-24 10:41:39 -0400
committerDrew DeVault <sir@cmpwn.com>2021-08-30 14:58:09 +0200
commit0b19b5e70e408bbaac5555b0b61a9451189406f8 (patch)
tree6fb8553af0b3b9626fddf8e6678f397c9bc0ea67
parentd39c6b449e96d5a431bc25189bf9e604eb2962d7 (diff)
downloadaerc-0b19b5e70e408bbaac5555b0b61a9451189406f8.tar.gz
lib/ui/textinput: Optimize ensureScroll
-rw-r--r--lib/ui/textinput.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go
index e96499a9..d179bce1 100644
--- a/lib/ui/textinput.go
+++ b/lib/ui/textinput.go
@@ -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
}
}