on main help sign in
fix(ui): list: countLines should return 1 for empty strings
03b18feAyman Bagabas
internal/ui/dialog/models_list.go+18
@@ -144,6 +144,24 @@ func (f *ModelsList) SelectLast() (v bool) {
144 }
144 }
145}
145}
146
146
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+
147// VisibleItems returns the visible items after filtering.
165// VisibleItems returns the visible items after filtering.
148func (f *ModelsList) VisibleItems() []list.Item {
166func (f *ModelsList) VisibleItems() []list.Item {
149 if f.query == "" {
167 if f.query == "" {
internal/ui/list/list.go+1−1
@@ -553,7 +553,7 @@ func (l *List) findItemAtY(_, y int) (itemIdx int, itemY int) {
553// countLines counts the number of lines in a string.
553// countLines counts the number of lines in a string.
554func countLines(s string) int {
554func countLines(s string) int {
555 if s == "" {
555 if s == "" {
556− return 0
556+ return 1
557 }
557 }
558 return strings.Count(s, "\n") + 1
558 return strings.Count(s, "\n") + 1
559}
559}