@@ -12,7 +12,6 @@ import (
12type ModelsList struct {
12type ModelsList struct {
13 *list.List
13 *list.List
14 groups []ModelGroup
14 groups []ModelGroup
16 query string
15 query string
17 t *styles.Styles
16 t *styles.Styles
@@ -30,6 +29,16 @@ func NewModelsList(sty *styles.Styles, groups ...ModelGroup) *ModelsList {
30// SetGroups sets the model groups and updates the list items.
29// SetGroups sets the model groups and updates the list items.
31func (f *ModelsList) SetGroups(groups ...ModelGroup) {
30func (f *ModelsList) SetGroups(groups ...ModelGroup) {
32 f.groups = groups
31 f.groups = groups
32+ items := []list.Item{}
33+ for _, g := range f.groups {
34+ items = append(items, &g)
35+ for _, item := range g.Items {
36+ items = append(items, item)
38+ // Add a space separator after each provider section
39+ items = append(items, list.NewSpacerItem(1))
41+ f.List.SetItems(items...)
35// SetFilter sets the filter query and updates the list items.
44// SetFilter sets the filter query and updates the list items.
@@ -39,6 +48,11 @@ func (f *ModelsList) SetFilter(q string) {
40// SetSelectedItem sets the selected item in the list by item ID.
49// SetSelectedItem sets the selected item in the list by item ID.
41func (f *ModelsList) SetSelectedItem(itemID string) {
50func (f *ModelsList) SetSelectedItem(itemID string) {
42 count := 0
56 count := 0
43 for _, g := range f.groups {
57 for _, g := range f.groups {
44 for _, item := range g.Items {
58 for _, item := range g.Items {
@@ -51,26 +65,6 @@ func (f *ModelsList) SetSelectedItem(itemID string) {
54−// SelectNext selects the next selectable item in the list.
55−func (f *ModelsList) SelectNext() bool {
56− for f.List.SelectNext() {
57− if _, ok := f.List.SelectedItem().(*ModelItem); ok {
64−// SelectPrev selects the previous selectable item in the list.
65−func (f *ModelsList) SelectPrev() bool {
66− for f.List.SelectPrev() {
67− if _, ok := f.List.SelectedItem().(*ModelItem); ok {
74// VisibleItems returns the visible items after filtering.
68// VisibleItems returns the visible items after filtering.
75func (f *ModelsList) VisibleItems() []list.Item {
69func (f *ModelsList) VisibleItems() []list.Item {
76 if len(f.query) == 0 {
70 if len(f.query) == 0 {
@@ -110,10 +104,11 @@ func (f *ModelsList) VisibleItems() []list.Item {
110 visitedGroups := map[int]bool{}
104 visitedGroups := map[int]bool{}
112 // Reconstruct groups with matched items
106 // Reconstruct groups with matched items
113− for _, match := range matches {
114− item := filterableItems[match.Index]
115− // Find which group this item belongs to
107+ // Find which group this item belongs to
116− for gi, g := range f.groups {
108+ for gi, g := range f.groups {
110+ for _, match := range matches {
111+ item := filterableItems[match.Index]
117 if slices.Contains(groupItems[gi], item.(*ModelItem)) {
112 if slices.Contains(groupItems[gi], item.(*ModelItem)) {
118 if !visitedGroups[gi] {
113 if !visitedGroups[gi] {
119 // Add section header
114 // Add section header
@@ -125,11 +120,14 @@ func (f *ModelsList) VisibleItems() []list.Item {
125 ms.SetMatch(match)
120 ms.SetMatch(match)
126 item = ms.(list.FilterableItem)
121 item = ms.(list.FilterableItem)
128− // Add a space separator after each provider section
129− items = append(items, item, list.NewSpacerItem(1))
123+ items = append(items, item)
130− break
124+ addedCount++
128+ // Add a space separator after each provider section
129+ items = append(items, list.NewSpacerItem(1))
135 return items
133 return items