Change summary
internal/ui/dialog/models_list.go | 18 ++++++++++++++++++
internal/ui/list/list.go | 2 +-
2 files changed, 19 insertions(+), 1 deletion(-)
Detailed changes
@@ -144,6 +144,24 @@ func (f *ModelsList) SelectLast() (v bool) {
}
}
+// IsSelectedFirst checks if the selected item is the first model item.
+func (f *ModelsList) IsSelectedFirst() bool {
+ originalIndex := f.List.Selected()
+ f.SelectFirst()
+ isFirst := f.List.Selected() == originalIndex
+ f.List.SetSelected(originalIndex)
+ return isFirst
+}
+
+// IsSelectedLast checks if the selected item is the last model item.
+func (f *ModelsList) IsSelectedLast() bool {
+ originalIndex := f.List.Selected()
+ f.SelectLast()
+ isLast := f.List.Selected() == originalIndex
+ f.List.SetSelected(originalIndex)
+ return isLast
+}
+
// VisibleItems returns the visible items after filtering.
func (f *ModelsList) VisibleItems() []list.Item {
if f.query == "" {
@@ -553,7 +553,7 @@ func (l *List) findItemAtY(_, y int) (itemIdx int, itemY int) {
// countLines counts the number of lines in a string.
func countLines(s string) int {
if s == "" {
- return 0
+ return 1
}
return strings.Count(s, "\n") + 1
}