From 89eaabe1e955f91f003491c104a3442150ec31cf Mon Sep 17 00:00:00 2001 From: Joseph Vidal Date: Wed, 18 Nov 2026 23:32:06 -0500 Subject: [PATCH 1/2] fix(shared): palette search finds a name by the end of its number --- packages/shared/src/paletteSearch.test.ts | 8 ++++++++ packages/shared/src/paletteSearch.ts | 21 +++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/shared/src/paletteSearch.test.ts b/packages/shared/src/paletteSearch.test.ts index c2fcbeba3316..4606973a6ca0 100644 --- a/packages/shared/src/paletteSearch.test.ts +++ b/packages/shared/src/paletteSearch.test.ts @@ -590,6 +590,14 @@ describe("rankSearchGroups with keywords and picks", () => { scoreThreadSearch("arch", thread("Notes", { branch: "research-extension-system" }), NOW), ).toBeNull(); expect(scoreThreadSearch("arch", thread("Research notes"), NOW)?.quality).toBe(0.3); + // Except a number's last digits in a name, never in a pull request number. + expect(scoreSearchTerms("120", ["33120", "/home/joseph/CMU/33120"])?.quality).toBe(0.3); + expect(scoreThreadSearch("120", thread("33120 notes"), NOW)?.quality).toBe(0.3); + expect(scoreSearchTerms("312", ["33120"])).toBeNull(); + expect(scoreSearchTerms("20", ["33120"])).toBeNull(); + expect( + scoreThreadSearch("189", thread("Stats", { pullRequests: [{ number: 22189 }] }), NOW), + ).toBeNull(); }); it("forgives typos in names but not in hidden keywords", () => { diff --git a/packages/shared/src/paletteSearch.ts b/packages/shared/src/paletteSearch.ts index a2de064ca496..6bfa448a140a 100644 --- a/packages/shared/src/paletteSearch.ts +++ b/packages/shared/src/paletteSearch.ts @@ -188,8 +188,22 @@ interface TokenMatch extends SearchRange { readonly letters?: ReadonlyArray; } +const NUMBER = /^\p{N}+$/u; + +// A name's number ends with what people remember of it: "120" finds course "33120". +function endsNumber(field: SearchField, token: string, index: number): boolean { + const end = index + token.length; + return ( + token.length >= 3 && + NUMBER.test(token) && + DIGIT.test(field.text[index - 1] ?? "") && + !DIGIT.test(field.text[end] ?? "") + ); +} + /** - * Mid-word hits need four or more characters and `midWord`, so "del" does not find "model". + * Mid-word hits need four or more characters and `midWord`, so "del" does not find "model", + * or a name's number ending in the token. * Typos preserve the first letter except for swaps; short tokens allow fewer edits to limit noise. * Numbers never match with a typo because different pull request numbers must stay distinct. */ @@ -227,7 +241,10 @@ function matchToken( best = { score, start: index, end: index + token.length }; } if (score === WHOLE_WORD) return best; - } else if (midWord && token.length >= 4 && best === null) { + } else if ( + best === null && + ((midWord && token.length >= 4) || (isPrimary && endsNumber(field, token, index))) + ) { best = { score: MID_WORD, start: index, end: index + token.length }; } } From b70c9416b041867a73a8ec091f226aa88d29ebbf Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 04:50:39 +0000 Subject: [PATCH 2/2] test(shared): use a neutral path in the number-suffix case Co-Authored-By: Claude Opus 5.5 --- packages/shared/src/paletteSearch.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/src/paletteSearch.test.ts b/packages/shared/src/paletteSearch.test.ts index 4606973a6ca0..364e34b0a0fa 100644 --- a/packages/shared/src/paletteSearch.test.ts +++ b/packages/shared/src/paletteSearch.test.ts @@ -591,7 +591,7 @@ describe("rankSearchGroups with keywords and picks", () => { ).toBeNull(); expect(scoreThreadSearch("arch", thread("Research notes"), NOW)?.quality).toBe(0.3); // Except a number's last digits in a name, never in a pull request number. - expect(scoreSearchTerms("120", ["33120", "/home/joseph/CMU/33120"])?.quality).toBe(0.3); + expect(scoreSearchTerms("120", ["33120", "~/courses/33120"])?.quality).toBe(0.3); expect(scoreThreadSearch("120", thread("33120 notes"), NOW)?.quality).toBe(0.3); expect(scoreSearchTerms("312", ["33120"])).toBeNull(); expect(scoreSearchTerms("20", ["33120"])).toBeNull();