@@ -138,7 +138,7 @@ func (l *List) ScrollBy(lines int) {
138 if l.gap > 0 && i < len(l.items)-1 {
138 if l.gap > 0 && i < len(l.items)-1 {
139 totalLines += l.gap
139 totalLines += l.gap
141− if totalLines >= l.height {
141+ if totalLines > l.height-1 {
142 lastItemIdx = i
142 lastItemIdx = i
@@ -165,7 +165,7 @@ func (l *List) ScrollBy(lines int) {
167 if l.offsetLine >= item.height {
167 if l.offsetLine >= item.height {
168− l.offsetLine = item.height - 1
168+ l.offsetLine = item.height
170 } else if lines < 0 {
170 } else if lines < 0 {
171 // Scroll up
171 // Scroll up
@@ -376,7 +376,36 @@ func (l *List) ScrollToBottom() {
377// ScrollToSelected scrolls the list to the selected item.
377// ScrollToSelected scrolls the list to the selected item.
378func (l *List) ScrollToSelected() {
378func (l *List) ScrollToSelected() {
379− // TODO: Implement me
379+ if l.selectedIdx < 0 || l.selectedIdx >= len(l.items) {
383+ startIdx, endIdx := l.findVisibleItems()
384+ if l.selectedIdx < startIdx {
385+ // Selected item is above the visible range
386+ l.offsetIdx = l.selectedIdx
388+ } else if l.selectedIdx > endIdx {
389+ // Selected item is below the visible range
390+ // Scroll so that the selected item is at the bottom
392+ for i := l.selectedIdx; i >= 0; i-- {
393+ item := l.getItem(i)
394+ totalHeight += item.height
395+ if l.gap > 0 && i < l.selectedIdx {
396+ totalHeight += l.gap
398+ if totalHeight >= l.height {
400+ l.offsetLine = totalHeight - l.height
404+ if totalHeight < l.height {
405+ // All items fit in the viewport
382// SelectedItemInView returns whether the selected item is currently in view.
411// SelectedItemInView returns whether the selected item is currently in view.