From 953d181984a5daf537bba6a7c713c343e2e55d6a Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Mon, 8 Dec 2025 19:42:03 -0500 Subject: [PATCH] feat(ui): optimize ScrollToBottom in lazylist --- internal/ui/lazylist/list.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/ui/lazylist/list.go b/internal/ui/lazylist/list.go index 70862f80b5efd6e3379c01676c1211b0b32221e0..4a2e47e02b6d8c677d5fecf9ee3fefb7c47f475a 100644 --- a/internal/ui/lazylist/list.go +++ b/internal/ui/lazylist/list.go @@ -336,8 +336,7 @@ func (l *List) ScrollToBottom() { // Scroll to the last item var totalHeight int - var i int - for i = len(l.items) - 1; i >= 0; i-- { + for i := len(l.items) - 1; i >= 0; i-- { item := l.getItem(i) totalHeight += item.height if l.gap > 0 && i < len(l.items)-1 { @@ -349,10 +348,9 @@ func (l *List) ScrollToBottom() { break } } - if i < 0 { + if totalHeight < l.height { // All items fit in the viewport - l.offsetIdx = 0 - l.offsetLine = 0 + l.ScrollToTop() } }