@@ -158,7 +158,7 @@ func (l *List) getItem(idx int) renderedItem {
158158
159159 rendered := item.Render(l.width)
160160 rendered = strings.TrimRight(rendered, "\n")
161− height := countLines(rendered)
161+ height := strings.Count(rendered, "\n") + 1
162162 ri := renderedItem{
163163 content: rendered,
164164 height: height,
@@ -190,13 +190,18 @@ func (l *List) ScrollBy(lines int) {
190190 }
191191
192192 if lines > 0 {
193+ if l.AtBottom() {
194+ // Already at bottom
195+ return
196+ }
197+
193198 // Scroll down
194199 l.offsetLine += lines
195200 currentItem := l.getItem(l.offsetIdx)
196201 for l.offsetLine >= currentItem.height {
197202 l.offsetLine -= currentItem.height
198203 if l.gap > 0 {
199− l.offsetLine -= l.gap
204+ l.offsetLine = max(0, l.offsetLine-l.gap)
200205 }
201206
202207 // Move to next item
@@ -219,14 +224,13 @@ func (l *List) ScrollBy(lines int) {
219224 // Scroll up
220225 l.offsetLine += lines // lines is negative
221226 for l.offsetLine < 0 {
222− if l.offsetIdx <= 0 {
227+ // Move to previous item
228+ l.offsetIdx--
229+ if l.offsetIdx < 0 {
223230 // Reached top
224231 l.ScrollToTop()
225232 break
226233 }
227−
228− // Move to previous item
229− l.offsetIdx--
230234 prevItem := l.getItem(l.offsetIdx)
231235 totalHeight := prevItem.height
232236 if l.gap > 0 {
@@ -642,11 +646,3 @@ func (l *List) findItemAtY(_, y int) (itemIdx int, itemY int) {
642646
643647 return -1, -1
644648}
645−
646−// countLines counts the number of lines in a string.
647−func countLines(s string) int {
648− if s == "" {
649− return 1
650− }
651− return strings.Count(s, "\n") + 1
652−}