Skip to content

Commit dd0b8b9

Browse files
JonasBaclaude
andcommitted
perf(cmdk): Score each candidate field individually in scoreNode
Instead of joining label, details, and keywords into a single string and running fzf once, score each field independently and return the best match. This has two benefits: - Avoids false cross-field subsequence matches that could arise when the tail of one field and the head of the next happen to satisfy a pattern across the join boundary. - Allows fzf's built-in exact-match bonus to fire naturally (e.g. when the query equals the label exactly), without needing a manual boost at the call site. Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
1 parent e2b0710 commit dd0b8b9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

static/app/components/commandPalette/ui/commandPalette.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,21 @@ function scoreNode(
420420
const label = node.display.label;
421421
const details = node.display.details ?? '';
422422
const keywords = node.keywords ?? [];
423-
const candidates = [label, details, ...keywords].join(' ');
424-
const result = fzf(candidates, query, false);
425-
return {matched: result.end !== -1, score: result.score};
423+
424+
// Score each field independently and take the best result. This lets
425+
// fzf's built-in exact-match bonus fire naturally (e.g. query === label)
426+
// and avoids false cross-field subsequence matches from string concatenation.
427+
let best = -Infinity;
428+
let matched = false;
429+
for (const candidate of [label, details, ...keywords]) {
430+
if (!candidate) continue;
431+
const result = fzf(candidate, query, false);
432+
if (result.end !== -1 && result.score > best) {
433+
best = result.score;
434+
matched = true;
435+
}
436+
}
437+
return {matched, score: matched ? best : 0};
426438
}
427439

428440
function scoreTree(

0 commit comments

Comments
 (0)