summaryrefslogtreecommitdiff
path: root/tui
diff options
context:
space:
mode:
authorcitrons <citrons@mondecitronne.com>2025-06-01 15:29:55 -0500
committercitrons <citrons@mondecitronne.com>2025-06-01 15:29:55 -0500
commit4351f6b505ceb9ba1a522e48bcd2b45647eb99a5 (patch)
treef66555ba27f27bc4d859e73117457b0467f274a7 /tui
parent9c20cc5895e9becbe066abab66d468e961af0467 (diff)
tui/layout.go: fix crash
Diffstat (limited to 'tui')
-rw-r--r--tui/layout.go26
1 files changed, 15 insertions, 11 deletions
diff --git a/tui/layout.go b/tui/layout.go
index 398c0b1..9acc65b 100644
--- a/tui/layout.go
+++ b/tui/layout.go
@@ -277,19 +277,23 @@ func (b *Box) computePositions(axis int) {
}
}
if b.Scroll != nil {
- first := b.children[0]
- last := b.children[len(b.children) - 1]
+ var first, last *Box
+ if len(b.children) > 0 {
+ first = b.children[0]
+ last = b.children[len(b.children) - 1]
+ }
- lastPos := last.computedPosition
- lastPos += last.computedSize[axis]
- if b.Dir.reverse() {
- lastPos = b.computedSize[axis] - lastPos
+ if last != nil {
+ lastPos := last.computedPosition
+ lastPos += last.computedSize[axis]
+ if b.Dir.reverse() {
+ lastPos = b.computedSize[axis] - lastPos
+ }
+ b.Scroll.absolute = min(b.Scroll.absolute, lastPos - b.computedSize[axis])
}
- b.Scroll.absolute = min(b.Scroll.absolute, lastPos - b.computedSize[axis])
b.Scroll.absolute = max(b.Scroll.absolute, 0)
- var firstShown *Box
- var lastShown *Box
+ var firstShown, lastShown *Box
for _, c := range b.children {
if !b.Dir.reverse() {
c.computedPosition -= b.Scroll.absolute
@@ -299,9 +303,9 @@ func (b *Box) computePositions(axis int) {
if c.computedPosition > b.computedRect.min[axis] &&
c.computedPosition < b.computedRect.max[axis] {
if firstShown == nil {
- first = c
+ firstShown = c
}
- last = c
+ lastShown = c
}
}
if firstShown == first {