@@ -259,25 +259,14 @@ func (l *List) ScrollBy(lines int) {
259259 }
260260 } else if lines < 0 {
261261 // Scroll up
262− // Calculate from offset how many items needed to fill the viewport
263− // This is needed to know when to stop scrolling up
264− var totalLines int
265− var firstItemIdx int
266− for i := l.offsetIdx; i >= 0; i-- {
267− item := l.getItem(i)
268− totalLines += item.height
269− if l.gap > 0 && i < l.offsetIdx {
270− totalLines += l.gap
271− }
272− if totalLines >= l.height {
273− firstItemIdx = i
262+ l.offsetLine += lines // lines is negative
263+ for l.offsetLine < 0 {
264+ if l.offsetIdx <= 0 {
265+ // Reached top
266+ l.ScrollToTop()
274267 break
275268 }
276− }
277269
278− // Now scroll up by lines
279− l.offsetLine += lines // lines is negative
280− for l.offsetIdx > firstItemIdx && l.offsetLine < 0 {
281270 // Move to previous item
282271 l.offsetIdx--
283272 prevItem := l.getItem(l.offsetIdx)
@@ -287,10 +276,6 @@ func (l *List) ScrollBy(lines int) {
287276 }
288277 l.offsetLine += totalHeight
289278 }
290−
291− if l.offsetLine < 0 {
292− l.offsetLine = 0
293− }
294279 }
295280}
296281