mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-23 21:16:06 +00:00
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:
parent
9b0659d4f9
commit
054bcdca43
1 changed files with 11 additions and 1 deletions
|
|
@ -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),
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue