Skip to content

Commit 1fcf5f6

Browse files
Merge branch 'main' into fix/web-sidebar-window-switch-motion
2 parents f157029 + 09a54f0 commit 1fcf5f6

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

‎packages/shared/src/paletteSearch.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,43 @@ describe("scoreThreadSearch", () => {
4040
thread("Share auth across worktrees"),
4141
]),
4242
).toEqual(["Share auth across worktrees", "Authentication cleanup", "Fix oauth redirect"]);
43+
expect(
44+
rankTitles("share auth", [
45+
thread("Share authentication cleanup", {
46+
activityAt: NOW,
47+
opens: { openedAt: NOW, score: 12, picks: [] },
48+
}),
49+
thread("Auth across worktrees to share", { activityAt: NOW - 90 * DAY }),
50+
]),
51+
).toEqual(["Auth across worktrees to share", "Share authentication cleanup"]);
52+
expect(
53+
rankTitles("ui", [
54+
thread("Parse ui tokens", { activityAt: NOW - 200 * DAY }),
55+
thread("Polish UIs", { activityAt: NOW, opens: { openedAt: NOW, score: 12, picks: [] } }),
56+
]),
57+
).toEqual(["Polish UIs", "Parse ui tokens"]);
58+
expect(
59+
rankTitles("fix in sidebar", [
60+
thread("Fix sidebar", { activityAt: NOW - 200 * DAY }),
61+
thread("Fix crash in sidebar", {
62+
activityAt: NOW,
63+
opens: { openedAt: NOW, score: 12, picks: [] },
64+
}),
65+
thread("Fix sidebar input focus", {
66+
activityAt: NOW,
67+
opens: { openedAt: NOW, score: 6, picks: [] },
68+
}),
69+
]),
70+
).toEqual(["Fix crash in sidebar", "Fix sidebar input focus", "Fix sidebar"]);
71+
expect(
72+
rankTitles("and", [
73+
thread("Fix auth and sync", { activityAt: NOW - 200 * DAY }),
74+
thread("Android build", {
75+
activityAt: NOW,
76+
opens: { openedAt: NOW, score: 12, picks: [] },
77+
}),
78+
]),
79+
).toEqual(["Android build", "Fix auth and sync"]);
4380
});
4481

4582
it("treats camelCase, kebab, path, and digit boundaries as word starts", () => {

‎packages/shared/src/paletteSearch.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,11 @@ interface WeightedSearchField {
344344
interface SearchFieldsMatch {
345345
/** Roughly 0.3 (inside a word) to 1.5 (exact title). */
346346
readonly quality: number;
347+
/**
348+
* Every non-filler token has three or more characters and matched a whole word at full
349+
* weight, before phrase bonuses. Optional filler words don't count either way.
350+
*/
351+
readonly wholeWords: boolean;
347352
/** Every token matched at a word start, without a typo. */
348353
readonly strong: boolean;
349354
/** Source ranges matched in the first field, for highlighting. */
@@ -407,6 +412,7 @@ function matchSearchFields(
407412
const primaryRanges: SearchRange[] = [];
408413
let total = 0;
409414
let counted = 0;
415+
let notWhole = false;
410416
let strong = true;
411417
for (const token of tokens) {
412418
let best = 0;
@@ -433,6 +439,9 @@ function matchSearchFields(
433439
if (bestPrimary) primaryRanges.push(...(bestPrimary.letters ?? [bestPrimary]));
434440
total += best;
435441
counted += 1;
442+
// Optional filler never decides the whole-word tier; a query of only filler never earns it.
443+
if (FILLER_WORDS.has(token)) notWhole ||= !fillerOptional;
444+
else notWhole ||= token.length < PICK_PREFIX_MIN_LENGTH || best < WHOLE_WORD;
436445
}
437446
let quality = total / counted;
438447
if (primary) {
@@ -441,6 +450,7 @@ function matchSearchFields(
441450
}
442451
return {
443452
quality,
453+
wholeWords: !notWhole,
444454
strong,
445455
primaryRanges: mergeRanges(primaryRanges),
446456
};
@@ -851,7 +861,7 @@ function matchReference(
851861
};
852862
return (thread.id && matches(thread.id)) ||
853863
thread.pullRequests?.some((pullRequest) => pullRequest.references?.some(matches))
854-
? { quality: 0.6, strong: true, primaryRanges: [] }
864+
? { quality: 0.6, wholeWords: false, strong: true, primaryRanges: [] }
855865
: null;
856866
}
857867

@@ -888,6 +898,7 @@ export interface ThreadSearchMatch {
888898
readonly score: number;
889899
/** Match quality alone; see `rankSearchGroups`. */
890900
readonly quality: number;
901+
readonly wholeWords: boolean;
891902
/** Every token matched at a word start; see `rankSearchGroups`. */
892903
readonly strong: boolean;
893904
/** Matched ranges in the title. */
@@ -1043,6 +1054,7 @@ export function scoreThreadSearch(
10431054
return {
10441055
score: match.quality * threadUsageBoost(thread, now),
10451056
quality: match.quality,
1057+
wholeWords: match.wholeWords,
10461058
// A thread's whole title never lifts its group over a command or project
10471059
// of that name: every new thread is titled "New thread" for a while.
10481060
groupQuality: Math.min(match.quality, WHOLE_NAME - 0.01),
@@ -1146,6 +1158,7 @@ export function rankSearchGroups<
11461158
readonly pickedAt?: number;
11471159
readonly pickedExactly?: boolean;
11481160
readonly groupQuality?: number;
1161+
readonly wholeWords?: boolean;
11491162
},
11501163
>(
11511164
groups: ReadonlyArray<{ readonly group: G; readonly items: ReadonlyArray<T> }>,
@@ -1173,12 +1186,15 @@ export function rankSearchGroups<
11731186
// A longer-query pick must not pass a whole-name match for the current query.
11741187
const wordMatch = (match: M) => Math.min(matchClass(match.quality), 2);
11751188
const exactPickAt = (match: M) => (match.pickedExactly ? (match.pickedAt ?? 0) : 0);
1189+
// Use reorders whole words or prefixes among themselves, never a prefix above a whole word.
1190+
const wholeWord = (match: M) => Number(match.wholeWords ?? match.quality >= WHOLE_WORD);
11761191
const sorted = [...items].sort(
11771192
(left, right) =>
11781193
wordMatch(right.match) - wordMatch(left.match) ||
11791194
exactPickAt(right.match) - exactPickAt(left.match) ||
11801195
matchClass(right.match.quality) - matchClass(left.match.quality) ||
11811196
(right.match.pickedAt ?? 0) - (left.match.pickedAt ?? 0) ||
1197+
wholeWord(right.match) - wholeWord(left.match) ||
11821198
right.match.score - left.match.score,
11831199
);
11841200
const best = Math.max(

0 commit comments

Comments
 (0)