Files
wehub-resource-sync ead81af521
Deploy to GitHub Pages / deploy (push) Failing after 0s
CI / go (push) Has been cancelled
CI / build (darwin, macos-14) (push) Has been cancelled
CI / build (windows, windows-2025) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:13 +08:00

32 lines
776 B
Go

package model
import (
"sort"
"github.com/bjarneo/cliamp/internal/fuzzy"
)
// updateSearch filters the playlist by the current search query, ranking
// matches by fuzzy relevance (best match first).
func (m *Model) updateSearch() {
m.search.results = nil
m.search.cursor = 0
m.search.scroll = 0
if m.search.query == "" {
return
}
type match struct{ idx, score int }
matches := make([]match, 0, m.playlist.Len())
for i, t := range m.playlist.Tracks() {
if score, ok := fuzzy.Match(m.search.query, t.DisplayName()); ok {
matches = append(matches, match{i, score})
}
}
sort.SliceStable(matches, func(a, b int) bool {
return matches[a].score > matches[b].score
})
for _, mt := range matches {
m.search.results = append(m.search.results, mt.idx)
}
}