on main help sign in
feat(ui): models dialog: filter by provider and model name
commitf5415908291cbb713943aa5f42b3f9e54a5cfa1c authorAyman Bagabas <ayman.bagabas@gmail.com> dateMon 5 Jan 2026, 16:09 (1 year ago) parent03b18fe
1 file changed+30−14
internal/ui/dialog/models_list.go+30−14
internal/ui/dialog/models_list.go+30−14
@@ -1,7 +1,10 @@
11package dialog
22
33import (
4+ "fmt"
45 "slices"
6+ "sort"
7+ "strings"
58
69 "github.com/charmbracelet/crush/internal/ui/list"
710 "github.com/charmbracelet/crush/internal/ui/styles"
@@ -186,16 +189,21 @@ func (f *ModelsList) VisibleItems() []list.Item {
186189 }
187190 }
188191
189− matches := fuzzy.FindFrom(f.query, list.FilterableItemsSource(filterableItems))
190− for _, match := range matches {
191− item := filterableItems[match.Index]
192− if ms, ok := item.(list.MatchSettable); ok {
193− ms.SetMatch(match)
194− item = ms.(list.FilterableItem)
195− }
196− filterableItems = append(filterableItems, item)
192+ filterValue := func(itm *ModelItem) string {
193+ return strings.ToLower(fmt.Sprintf("%s %s", itm.prov.Name, itm.model.Name))
194+ }
195+
196+ names := make([]string, len(filterableItems))
197+ for i, item := range filterableItems {
198+ ms := item.(*ModelItem)
199+ names[i] = filterValue(ms)
197200 }
198201
202+ matches := fuzzy.Find(f.query, names)
203+ sort.SliceStable(matches, func(i, j int) bool {
204+ return matches[i].Score > matches[j].Score
205+ })
206+
199207 items := []list.Item{}
200208 visitedGroups := map[int]bool{}
201209
@@ -203,19 +211,27 @@ func (f *ModelsList) VisibleItems() []list.Item {
203211 // Find which group this item belongs to
204212 for gi, g := range f.groups {
205213 addedCount := 0
214+ name := g.Title + " "
206215 for _, match := range matches {
207− item := filterableItems[match.Index]
208− if slices.Contains(g.Items, item.(*ModelItem)) {
216+ item := filterableItems[match.Index].(*ModelItem)
217+ idxs := []int{}
218+ for _, idx := range match.MatchedIndexes {
219+ // Adjusts removing provider name highlights
220+ if idx < len(name) {
221+ continue
222+ }
223+ idxs = append(idxs, idx-len(name))
224+ }
225+
226+ match.MatchedIndexes = idxs
227+ if slices.Contains(g.Items, item) {
209228 if !visitedGroups[gi] {
210229 // Add section header
211230 items = append(items, &g)
212231 visitedGroups[gi] = true
213232 }
214233 // Add the matched item
215− if ms, ok := item.(list.MatchSettable); ok {
216− ms.SetMatch(match)
217− item = ms.(list.FilterableItem)
218− }
234+ item.SetMatch(match)
219235 items = append(items, item)
220236 addedCount++
221237 }