on main help sign in
fix(ui): models dialog: filter each group separately
909244eAyman Bagabas
internal/ui/dialog/models_list.go+13−16
@@ -191,21 +191,6 @@ func (f *ModelsList) VisibleItems() []list.Item {
191 }
191 }
192 }
192 }
193
193
194− filterValue := func(itm *ModelItem) string {
195− return strings.ToLower(fmt.Sprintf("%s %s", itm.prov.Name, itm.model.Name))
196− }
197−
198− names := make([]string, len(filterableItems))
199− for i, item := range filterableItems {
200− ms := item.(*ModelItem)
201− names[i] = filterValue(ms)
202− }
203−
204− matches := fuzzy.Find(query, names)
205− sort.SliceStable(matches, func(i, j int) bool {
206− return matches[i].Score > matches[j].Score
207− })
208−
209 items := []list.Item{}
194 items := []list.Item{}
210 visitedGroups := map[int]bool{}
195 visitedGroups := map[int]bool{}
211
196
@@ -213,7 +198,19 @@ func (f *ModelsList) VisibleItems() []list.Item {
213 // Find which group this item belongs to
198 // Find which group this item belongs to
214 for gi, g := range f.groups {
199 for gi, g := range f.groups {
215 addedCount := 0
200 addedCount := 0
216− name := g.Title + " "
201+ name := strings.ToLower(g.Title) + " "
202+
203+ names := make([]string, len(filterableItems))
204+ for i, item := range filterableItems {
205+ ms := item.(*ModelItem)
206+ names[i] = fmt.Sprintf("%s%s", name, ms.Filter())
207+ }
208+
209+ matches := fuzzy.Find(query, names)
210+ sort.SliceStable(matches, func(i, j int) bool {
211+ return matches[i].Score > matches[j].Score
212+ })
213+
217 for _, match := range matches {
214 for _, match := range matches {
218 item := filterableItems[match.Index].(*ModelItem)
215 item := filterableItems[match.Index].(*ModelItem)
219 idxs := []int{}
216 idxs := []int{}