on main help sign in
fix: allow searching by provider name
6da6c7dkujtimiihoxha
internal/tui/exp/list/filterable.go+2−6
@@ -15,12 +15,8 @@ import (
15 "github.com/sahilm/fuzzy"
15 "github.com/sahilm/fuzzy"
16)
16)
17
17
18−var (
19− // Pre-compiled regex for checking if a string contains alphabetic characters.
20− alphaRegex = regexp.MustCompile(`[a-zA-Z]`)
21− // Pre-compiled regex for checking if a string is alphanumeric.
18+// Pre-compiled regex for checking if a string is alphanumeric.
22− alphanumericRegex = regexp.MustCompile(`^[a-zA-Z0-9]*$`)
19+var alphanumericRegex = regexp.MustCompile(`^[a-zA-Z0-9]*$`)
23−)
24
20
25type FilterableItem interface {
21type FilterableItem interface {
26 Item
22 Item
internal/tui/exp/list/filterable_group.go+46−19
@@ -198,30 +198,57 @@ func (f *filterableGroupList[T]) Filter(query string) tea.Cmd {
198
198
199 var newGroups []Group[T]
199 var newGroups []Group[T]
200 for _, g := range f.groups {
200 for _, g := range f.groups {
201− words := make([]string, len(g.Items))
201+ // Check if group name matches the query
202− for i, item := range g.Items {
202+ // Extract the group name from the section - we'll use the section's view content
203+ // as a fallback since ItemSection doesn't implement FilterableItem
204+ var groupName string
205+ if section, ok := g.Section.(*itemSectionModel); ok {
206+ groupName = strings.ToLower(section.title)
207+ } else {
208+ // Fallback to using the section's ID or view content
203− words[i] = strings.ToLower(item.FilterValue())
209+ groupName = strings.ToLower(g.Section.ID())
204 }
210 }
205−
206− matches := fuzzy.Find(query, words)
211+ groupMatches := fuzzy.Find(query, []string{groupName})
207−
212+
208− sort.SliceStable(matches, func(i, j int) bool {
213+ if len(groupMatches) > 0 && groupMatches[0].Score > 0 {
209− return matches[i].Score > matches[j].Score
214+ // If group name matches, include all items from this group
210− })
215+ // Clear any existing match indexes for items since the group matched
211−
212− var matchedItems []T
213− for _, match := range matches {
216+ for _, item := range g.Items {
214− item := g.Items[match.Index]
215− if i, ok := any(item).(HasMatchIndexes); ok {
217+ if i, ok := any(item).(HasMatchIndexes); ok {
216− i.MatchIndexes(match.MatchedIndexes)
218+ i.MatchIndexes(make([]int, 0))
219+ }
217 }
220 }
218− matchedItems = append(matchedItems, item)
219− }
220− if len(matchedItems) > 0 {
221 newGroups = append(newGroups, Group[T]{
221 newGroups = append(newGroups, Group[T]{
222 Section: g.Section,
222 Section: g.Section,
223− Items: matchedItems,
223+ Items: g.Items,
224 })
224 })
225+ } else {
226+ // Group name doesn't match, check individual items
227+ words := make([]string, len(g.Items))
228+ for i, item := range g.Items {
229+ words[i] = strings.ToLower(item.FilterValue())
230+ }
231+
232+ matches := fuzzy.Find(query, words)
233+
234+ sort.SliceStable(matches, func(i, j int) bool {
235+ return matches[i].Score > matches[j].Score
236+ })
237+
238+ var matchedItems []T
239+ for _, match := range matches {
240+ item := g.Items[match.Index]
241+ if i, ok := any(item).(HasMatchIndexes); ok {
242+ i.MatchIndexes(match.MatchedIndexes)
243+ }
244+ matchedItems = append(matchedItems, item)
245+ }
246+ if len(matchedItems) > 0 {
247+ newGroups = append(newGroups, Group[T]{
248+ Section: g.Section,
249+ Items: matchedItems,
250+ })
251+ }
225 }
252 }
226 }
253 }
227 cmds = append(cmds, f.groupedList.SetGroups(newGroups))
254 cmds = append(cmds, f.groupedList.SetGroups(newGroups))