tui: boost favorites and recents when filtering model dialog

When the user types a query in the model selection dialog, favorites
and recents previously lost all positional priority and were ranked
purely by fuzzysort score on title/category. Now matching favorites
float to the top, followed by matching recents, then everything else,
each group preserving fuzzysort order.
This commit is contained in:
Kit Langton
2026-04-17 15:51:11 -04:00
parent 9b0659d4f9
commit 054bcdca43

View File

@@ -119,8 +119,18 @@ export function DialogModel(props: { providerID?: string }) {
: []
if (needle) {
const isFavorite = (v: { providerID: string; modelID: string }) =>
favorites.some((f) => f.providerID === v.providerID && f.modelID === v.modelID)
const isRecent = (v: { providerID: string; modelID: string }) =>
recents.some((r) => r.providerID === v.providerID && r.modelID === v.modelID)
const matches = fuzzysort.go(needle, providerOptions, { keys: ["title", "category"] }).map((x) => x.obj)
const fav = matches.filter((x) => isFavorite(x.value))
const rec = matches.filter((x) => !isFavorite(x.value) && isRecent(x.value))
const rest = matches.filter((x) => !isFavorite(x.value) && !isRecent(x.value))
return [
...fuzzysort.go(needle, providerOptions, { keys: ["title", "category"] }).map((x) => x.obj),
...fav,
...rec,
...rest,
...fuzzysort.go(needle, popularProviders, { keys: ["title"] }).map((x) => x.obj),
]
}