on main help sign in
feat(ui): optimize ScrollToBottom in lazylist
953d181Ayman Bagabas
internal/ui/lazylist/list.go+3−5
@@ -336,8 +336,7 @@ func (l *List) ScrollToBottom() {
336
336
337 // Scroll to the last item
337 // Scroll to the last item
338 var totalHeight int
338 var totalHeight int
339− var i int
340− for i = len(l.items) - 1; i >= 0; i-- {
339+ for i := len(l.items) - 1; i >= 0; i-- {
341 item := l.getItem(i)
340 item := l.getItem(i)
342 totalHeight += item.height
341 totalHeight += item.height
343 if l.gap > 0 && i < len(l.items)-1 {
342 if l.gap > 0 && i < len(l.items)-1 {
@@ -349,10 +348,9 @@ func (l *List) ScrollToBottom() {
349 break
348 break
350 }
349 }
351 }
350 }
352− if i < 0 {
351+ if totalHeight < l.height {
353 // All items fit in the viewport
352 // All items fit in the viewport
354− l.offsetIdx = 0
353+ l.ScrollToTop()
355− l.offsetLine = 0
356 }
354 }
357}
355}
358
356