on main help sign in
fix(ui): correct scrolling up behavior in lazy list
e2a586cAyman Bagabas
internal/ui/lazylist/list.go+5−20
@@ -259,25 +259,14 @@ func (l *List) ScrollBy(lines int) {
259 }
259 }
260 } else if lines < 0 {
260 } else if lines < 0 {
261 // Scroll up
261 // Scroll up
262− // Calculate from offset how many items needed to fill the viewport
262+ l.offsetLine += lines // lines is negative
263− // This is needed to know when to stop scrolling up
263+ for l.offsetLine < 0 {
264− var totalLines int
265− var firstItemIdx int
266− for i := l.offsetIdx; i >= 0; i-- {
264+ if l.offsetIdx <= 0 {
267− item := l.getItem(i)
265+ // Reached top
268− totalLines += item.height
266+ l.ScrollToTop()
269− if l.gap > 0 && i < l.offsetIdx {
270− totalLines += l.gap
271− }
272− if totalLines >= l.height {
273− firstItemIdx = i
274 break
267 break
275 }
268 }
276− }
277
269
278− // Now scroll up by lines
279− l.offsetLine += lines // lines is negative
280− for l.offsetIdx > firstItemIdx && l.offsetLine < 0 {
281 // Move to previous item
270 // Move to previous item
282 l.offsetIdx--
271 l.offsetIdx--
283 prevItem := l.getItem(l.offsetIdx)
272 prevItem := l.getItem(l.offsetIdx)
@@ -287,10 +276,6 @@ func (l *List) ScrollBy(lines int) {
287 }
276 }
288 l.offsetLine += totalHeight
277 l.offsetLine += totalHeight
289 }
278 }
290−
291− if l.offsetLine < 0 {
292− l.offsetLine = 0
293− }
294 }
279 }
295}
280}
296
281