@@ -12,7 +12,6 @@ import (
1212type ModelsList struct {
1313 *list.List
1414 groups []ModelGroup
15− items []list.Item
1615 query string
1716 t *styles.Styles
1817}
@@ -30,6 +29,16 @@ func NewModelsList(sty *styles.Styles, groups ...ModelGroup) *ModelsList {
3029// SetGroups sets the model groups and updates the list items.
3130func (f *ModelsList) SetGroups(groups ...ModelGroup) {
3231 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)
37+ }
38+ // Add a space separator after each provider section
39+ items = append(items, list.NewSpacerItem(1))
40+ }
41+ f.List.SetItems(items...)
3342}
3443
3544// SetFilter sets the filter query and updates the list items.
@@ -39,6 +48,11 @@ func (f *ModelsList) SetFilter(q string) {
3948
4049// SetSelectedItem sets the selected item in the list by item ID.
4150func (f *ModelsList) SetSelectedItem(itemID string) {
51+ if itemID == "" {
52+ f.SetSelected(0)
53+ return
54+ }
55+
4256 count := 0
4357 for _, g := range f.groups {
4458 for _, item := range g.Items {
@@ -51,26 +65,6 @@ func (f *ModelsList) SetSelectedItem(itemID string) {
5165 }
5266}
5367
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 {
58− return true
59− }
60− }
61− return false
62−}
63−
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 {
68− return true
69− }
70− }
71− return false
72−}
73−
7468// VisibleItems returns the visible items after filtering.
7569func (f *ModelsList) VisibleItems() []list.Item {
7670 if len(f.query) == 0 {
@@ -110,10 +104,11 @@ func (f *ModelsList) VisibleItems() []list.Item {
110104 visitedGroups := map[int]bool{}
111105
112106 // Reconstruct groups with matched items
113− for _, match := range matches {
114− item := filterableItems[match.Index]
115− // Find which group this item belongs to
116− for gi, g := range f.groups {
107+ // Find which group this item belongs to
108+ for gi, g := range f.groups {
109+ addedCount := 0
110+ for _, match := range matches {
111+ item := filterableItems[match.Index]
117112 if slices.Contains(groupItems[gi], item.(*ModelItem)) {
118113 if !visitedGroups[gi] {
119114 // Add section header
@@ -125,11 +120,14 @@ func (f *ModelsList) VisibleItems() []list.Item {
125120 ms.SetMatch(match)
126121 item = ms.(list.FilterableItem)
127122 }
128− // Add a space separator after each provider section
129− items = append(items, item, list.NewSpacerItem(1))
130− break
123+ items = append(items, item)
124+ addedCount++
131125 }
132126 }
127+ if addedCount > 0 {
128+ // Add a space separator after each provider section
129+ items = append(items, list.NewSpacerItem(1))
130+ }
133131 }
134132
135133 return items