fix(ui): early exit AtBottom() when totalHeight exceeds viewport height

Ayman Bagabas created

Related: https://github.com/charmbracelet/crush/issues/2226

Change summary

internal/ui/list/list.go | 4 ++++
1 file changed, 4 insertions(+)

Detailed changes

internal/ui/list/list.go 🔗

@@ -84,6 +84,10 @@ func (l *List) AtBottom() bool {
 	// Calculate the height from offsetIdx to the end.
 	var totalHeight int
 	for idx := l.offsetIdx; idx < len(l.items); idx++ {
+		if totalHeight > l.height {
+			// No need to calculate further, we're already past the viewport height
+			return false
+		}
 		item := l.getItem(idx)
 		itemHeight := item.height
 		if l.gap > 0 && idx > l.offsetIdx {