Skip to content

Commit 510f595

Browse files
authored
fix(tui): add weight to fuzzy search to maintain title priority (anomalyco#10106)
1 parent 1b244bf commit 510f595

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

packages/opencode/src/cli/cmd/tui/ui/dialog-select.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,23 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
7272
let input: InputRenderable
7373

7474
const filtered = createMemo(() => {
75-
if (props.skipFilter) {
76-
return props.options.filter((x) => x.disabled !== true)
77-
}
75+
if (props.skipFilter) return props.options.filter((x) => x.disabled !== true)
7876
const needle = store.filter.toLowerCase()
79-
const result = pipe(
77+
const options = pipe(
8078
props.options,
8179
filter((x) => x.disabled !== true),
82-
(x) => (!needle ? x : fuzzysort.go(needle, x, { keys: ["title", "category"] }).map((x) => x.obj)),
8380
)
81+
if (!needle) return options
82+
83+
// prioritize title matches (weight: 2) over category matches (weight: 1).
84+
// users typically search by the item name, and not its category.
85+
const result = fuzzysort
86+
.go(needle, options, {
87+
keys: ["title", "category"],
88+
scoreFn: (r) => r[0].score * 2 + r[1].score,
89+
})
90+
.map((x) => x.obj)
91+
8492
return result
8593
})
8694

0 commit comments

Comments
 (0)