Skip to content

Commit 55081a1

Browse files
fix(shared): thread search ignores the t3 prefix of flat temporary branches (#35430)
1 parent 60c3b22 commit 55081a1

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,14 @@ describe("scoreThreadSearch beyond Latin text and titles", () => {
333333
ranges: [{ start: 0, end: 7 }],
334334
});
335335
expect(scoreThreadSearch("trim", subject, NOW)?.explain?.()).toBeUndefined();
336+
// Nor is it in the flat t3-<hex> form used when a `t3` branch blocks nested refs.
337+
const flat = thread("Add search", { branch: "t3-abcd1234" });
338+
expect(scoreThreadSearch("t3", flat, NOW)).toBeNull();
339+
expect(scoreThreadSearch("t3 connect", flat, NOW)).toBeNull();
340+
expect(scoreThreadSearch("abcd1234", flat, NOW)).not.toBeNull();
341+
for (const query of ["t3-abcd", "t3-abcd1234 connect", "connect t3-abcd1234"]) {
342+
expect(scoreThreadSearch(query, { ...flat, projectTitle: "connect" }, NOW)).not.toBeNull();
343+
}
336344
});
337345

338346
it("reads letters and numbers typed together, without forgiving typos in numbers", () => {

‎packages/shared/src/paletteSearch.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -923,9 +923,19 @@ export interface SearchMatchHint {
923923
}
924924

925925
// Most threads' branches start with the app's own worktree prefix ("t3/", and
926-
// "t3code/" before it), so "t3 connect" would match nearly every thread.
926+
// "t3code/" before it, "t3-<hex>" when a "t3" branch blocks nested refs), so
927+
// "t3 connect" would match nearly every thread.
927928
// Only before more text, so typing "t3/" does not empty the list for a keystroke.
928-
const WORKTREE_BRANCH_PREFIX_PATTERN = new RegExp(`^(?:${WORKTREE_BRANCH_PREFIX}|t3code)/(?=\\S)`);
929+
const WORKTREE_BRANCH_PREFIX_PATTERN = new RegExp(
930+
`^(?:(?:${WORKTREE_BRANCH_PREFIX}|t3code)/(?=\\S)|${WORKTREE_BRANCH_PREFIX}-(?=[0-9a-f]{8}$))`,
931+
);
932+
933+
// The flat prefix anywhere in a query, while its hex is still being typed, so
934+
// "t3-abcd" and "connect t3-abcd1234" still reach the stripped branch field.
935+
const FLAT_BRANCH_QUERY_PREFIX_PATTERN = new RegExp(
936+
`(^| )${WORKTREE_BRANCH_PREFIX}-(?=[0-9a-f]{1,8}(?: |$))`,
937+
"g",
938+
);
929939

930940
function searchableBranch(branch: string | null | undefined): string | null {
931941
return branch ? branch.replace(WORKTREE_BRANCH_PREFIX_PATTERN, "") : null;
@@ -1005,7 +1015,8 @@ function threadFieldQuery(normalizedQuery: string): string {
10051015
fieldQuery: normalizedQuery
10061016
.replace(/^(?:pr|pull request|pull)\s*(?=#?\d)/, "")
10071017
.replace(/^#\s*/, "")
1008-
.replace(WORKTREE_BRANCH_PREFIX_PATTERN, ""),
1018+
.replace(WORKTREE_BRANCH_PREFIX_PATTERN, "")
1019+
.replace(FLAT_BRANCH_QUERY_PREFIX_PATTERN, "$1"),
10091020
};
10101021
}
10111022
return lastFieldQuery.fieldQuery;

0 commit comments

Comments
 (0)