diff options
| author | Idris Gadi <[email protected]> | 2026-01-23 03:45:11 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-01-22 16:15:11 -0600 |
| commit | 510f595e25ae4a1d9873bca73fddfd45e0337002 (patch) | |
| tree | c4fb1509f6476d274930e21f76d815b2d63ee5b5 | |
| parent | 1b244bf85030f5bb10009a953906af6d8ae9fc3e (diff) | |
| download | opencode-510f595e25ae4a1d9873bca73fddfd45e0337002.tar.gz opencode-510f595e25ae4a1d9873bca73fddfd45e0337002.zip | |
fix(tui): add weight to fuzzy search to maintain title priority (#10106)
| -rw-r--r-- | packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx b/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx index 618bf3b3c..173572233 100644 --- a/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx +++ b/packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx @@ -72,15 +72,23 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) { let input: InputRenderable const filtered = createMemo(() => { - if (props.skipFilter) { - return props.options.filter((x) => x.disabled !== true) - } + if (props.skipFilter) return props.options.filter((x) => x.disabled !== true) const needle = store.filter.toLowerCase() - const result = pipe( + const options = pipe( props.options, filter((x) => x.disabled !== true), - (x) => (!needle ? x : fuzzysort.go(needle, x, { keys: ["title", "category"] }).map((x) => x.obj)), ) + if (!needle) return options + + // prioritize title matches (weight: 2) over category matches (weight: 1). + // users typically search by the item name, and not its category. + const result = fuzzysort + .go(needle, options, { + keys: ["title", "category"], + scoreFn: (r) => r[0].score * 2 + r[1].score, + }) + .map((x) => x.obj) + return result }) |
