on main help sign in
fix(ui): list: countLines should return 1 for empty strings
commit03b18fe755acf77f5e10b9000ed7a2cf605af465 authorAyman Bagabas <ayman.bagabas@gmail.com> dateMon 5 Jan 2026, 14:41 (1 year ago) parent4e541e1
2 files changed+19−1
internal/ui/dialog/models_list.go+18 internal/ui/list/list.go+1−1
internal/ui/dialog/models_list.go+18
@@ -144,6 +144,24 @@ func (f *ModelsList) SelectLast() (v bool) {
144144 }
145145}
146146
147+// IsSelectedFirst checks if the selected item is the first model item.
148+func (f *ModelsList) IsSelectedFirst() bool {
149+ originalIndex := f.List.Selected()
150+ f.SelectFirst()
151+ isFirst := f.List.Selected() == originalIndex
152+ f.List.SetSelected(originalIndex)
153+ return isFirst
154+}
155+
156+// IsSelectedLast checks if the selected item is the last model item.
157+func (f *ModelsList) IsSelectedLast() bool {
158+ originalIndex := f.List.Selected()
159+ f.SelectLast()
160+ isLast := f.List.Selected() == originalIndex
161+ f.List.SetSelected(originalIndex)
162+ return isLast
163+}
164+
147165// VisibleItems returns the visible items after filtering.
148166func (f *ModelsList) VisibleItems() []list.Item {
149167 if f.query == "" {
internal/ui/list/list.go+1−1
@@ -553,7 +553,7 @@ func (l *List) findItemAtY(_, y int) (itemIdx int, itemY int) {
553553// countLines counts the number of lines in a string.
554554func countLines(s string) int {
555555 if s == "" {
556− return 0
556+ return 1
557557 }
558558 return strings.Count(s, "\n") + 1
559559}