The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): preserve server matches in file search (#18388)
Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: GPT-6.1 Sol <noreply@openai.com>
Alex Southwell committed
Oct 19, 2026 at 06:27 UTC
95c99a5e751a6eb1b94c5e2f6baccc7cb6c64bfb
6 files changed
+41
-102
apps/mobile/src/features/files/FileTreeBrowser.tsx
+3
-2
@@ -110,6 +110,7 @@ export function FileTreeBrowser(props: {
110
readonly isPending: boolean;
111
readonly isRefreshing: boolean;
112
readonly searchQuery: string;
113
+ readonly searchResultPaths: ReadonlySet<string> | null;
114
readonly searchTruncated: boolean;
115
readonly selectedPath: string | null;
116
readonly loadingDirectories: ReadonlySet<string>;
@@ -147,9 +148,9 @@ export function FileTreeBrowser(props: {
148
flattenFileTree({
149
nodes: tree,
150
expanded: expandedPaths,
150
- searchQuery: props.searchQuery,
151
+ searchResultPaths: props.searchResultPaths,
152
}),
152
- [expandedPaths, props.searchQuery, tree],
153
+ [expandedPaths, props.searchResultPaths, tree],
154
);
155
156
useEffect(() => {
apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx
+1
@@ -567,6 +567,7 @@ export function ThreadFilesTreeScreen(props: ThreadFilesRouteScreenProps) {
567
isPending={entriesQuery.isPending}
568
isRefreshing={entriesQuery.isRefreshing}
569
searchQuery={searchQuery}
570
+ searchResultPaths={entriesQuery.searchResultPaths}
571
searchTruncated={entriesQuery.searchTruncated}
572
selectedPath={null}
573
onPreviewFile={handlePreviewFile}
apps/mobile/src/features/files/fileTree.test.ts
+20
-35
@@ -51,46 +51,31 @@ describe("mobile file tree helpers", () => {
51
flattenFileTree({
52
nodes: tree,
53
expanded: new Set(),
54
- searchQuery: "app",
54
+ searchResultPaths: new Set(["src/components/App.tsx"]),
55
}).map((item) => item.node.path),
56
).toEqual(["src", "src/components", "src/components/App.tsx"]);
57
});
58
59
- it("supports fuzzy, whitespace-separated path queries", () => {
60
- const tree = buildFileTree([
61
- {
62
- kind: "file",
63
- path: "docs/internals/workspace-layout.md",
64
- },
65
- {
66
- kind: "file",
67
- path: ".repos/alchemy-effect/examples/aws-lambda/src/JobNotifications.ts",
68
- },
69
- { kind: "directory", path: "apps/web/src/components/chat" },
70
- { kind: "file", path: "apps/web/src/components/chat/ChatHeader.test.ts" },
71
- { kind: "file", path: "apps/web/src/components/chat/ChatHeader.tsx" },
72
- { kind: "file", path: "apps/web/src/components/chat/Composer.tsx" },
73
- ]);
74
-
75
- const expectedPaths = [
76
- "apps",
77
- "apps/web",
78
- "apps/web/src",
79
- "apps/web/src/components",
80
- "apps/web/src/components/chat",
81
- "apps/web/src/components/chat/ChatHeader.test.ts",
82
- "apps/web/src/components/chat/ChatHeader.tsx",
83
- ];
59
+ it("excludes cached children of matched directories", () => {
60
+ expect(
61
+ flattenFileTree({
62
+ nodes: buildFileTree(entries),
63
+ expanded: new Set(["src", "src/components"]),
64
+ searchResultPaths: new Set(["src/components"]),
65
+ }).map((item) => item.node.path),
66
+ ).toEqual(["src", "src/components"]);
67
+ });
68
85
- for (const searchQuery of ["chat hea", "cht hdr"]) {
86
- expect(
87
- flattenFileTree({
88
- nodes: tree,
89
- expanded: new Set(),
90
- searchQuery,
91
- }).map((item) => item.node.path),
92
- ).toEqual(expectedPaths);
93
- }
69
+ it("keeps an empty search empty and restores expansion when search clears", () => {
70
+ const tree = buildFileTree(entries);
71
+ expect(
72
+ flattenFileTree({ nodes: tree, expanded: new Set(["src"]), searchResultPaths: new Set() }),
73
+ ).toEqual([]);
74
+ expect(
75
+ flattenFileTree({ nodes: tree, expanded: new Set(), searchResultPaths: null }).map(
76
+ (item) => item.node.path,
77
+ ),
78
+ ).toEqual(["src", "package.json", "README.md"]);
79
});
80
81
it("expands top-level directories by default", () => {
apps/mobile/src/features/files/fileTree.ts
+7
-64
@@ -1,5 +1,4 @@
1
import type { ProjectEntry } from "@t3tools/contracts";
2
-import { normalizeSearchQuery, scoreQueryMatch } from "@t3tools/shared/searchRanking";
2
3
export interface FileTreeNode {
4
readonly path: string;
@@ -7,8 +6,6 @@ export interface FileTreeNode {
6
readonly kind: ProjectEntry["kind"];
7
readonly ignored?: boolean;
8
readonly children: ReadonlyArray<FileTreeNode>;
10
- readonly searchSegments: ReadonlyArray<string>;
11
- readonly searchWords: ReadonlyArray<string>;
9
}
10
11
export interface VisibleFileTreeNode {
@@ -37,43 +34,13 @@ function createMutableNode(
34
};
35
}
36
40
-function splitSearchWords(value: string): ReadonlyArray<string> {
41
- return value
42
- .replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2")
43
- .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
44
- .split(/[^A-Za-z0-9]+/)
45
- .filter(Boolean)
46
- .map((word) => word.toLowerCase());
47
-}
48
-
49
-function buildNodeSearchTerms(path: string): {
50
- readonly segments: ReadonlyArray<string>;
51
- readonly words: ReadonlyArray<string>;
52
-} {
53
- const segments: string[] = [];
54
- const words: string[] = [];
55
-
56
- for (const segment of path.split("/")) {
57
- if (!segment) {
58
- continue;
59
- }
60
- segments.push(segment.toLowerCase());
61
- words.push(...splitSearchWords(segment));
62
- }
63
-
64
- return { segments, words };
65
-}
66
-
37
function freezeNode(node: MutableFileTreeNode): FileTreeNode {
68
- const searchTerms = buildNodeSearchTerms(node.path);
38
return {
39
path: node.path,
40
name: node.name,
41
kind: node.kind,
42
...(node.ignored ? { ignored: true } : {}),
43
children: [...node.children.values()].sort(compareNodes).map(freezeNode),
75
- searchSegments: searchTerms.segments,
76
- searchWords: searchTerms.words,
44
};
45
}
46
@@ -133,44 +100,21 @@ export function defaultExpandedTreePaths(nodes: ReadonlyArray<FileTreeNode>): Re
100
return expanded;
101
}
102
136
-function valueMatchesSearchToken(value: string, token: string, fuzzy: boolean): boolean {
137
- return (
138
- scoreQueryMatch({
139
- value,
140
- query: token,
141
- exactBase: 0,
142
- prefixBase: 2,
143
- boundaryBase: 4,
144
- includesBase: 6,
145
- ...(fuzzy ? { fuzzyBase: 100 } : {}),
146
- boundaryMarkers: ["/", "-", "_", "."],
147
- }) !== null
148
- );
149
-}
150
-
151
-function nodeMatchesSearch(node: FileTreeNode, tokens: ReadonlyArray<string>): boolean {
152
- return tokens.every(
153
- (token) =>
154
- node.searchSegments.some((segment) => valueMatchesSearchToken(segment, token, false)) ||
155
- node.searchWords.some((word) => valueMatchesSearchToken(word, token, true)),
156
- );
157
-}
158
-
103
function flattenNode(
104
output: VisibleFileTreeNode[],
105
node: FileTreeNode,
106
depth: number,
107
expanded: ReadonlySet<string>,
164
- searchTokens: ReadonlyArray<string>,
108
+ searchResultPaths: ReadonlySet<string> | null,
109
): boolean {
166
- const isSearching = searchTokens.length > 0;
167
- const matches = isSearching && nodeMatchesSearch(node, searchTokens);
110
+ const isSearching = searchResultPaths !== null;
111
+ const matches = searchResultPaths?.has(node.path) ?? false;
112
let descendantMatches = false;
113
const childOutput: VisibleFileTreeNode[] = [];
114
115
if (node.kind === "directory" && (expanded.has(node.path) || isSearching)) {
116
for (const child of node.children) {
173
- if (flattenNode(childOutput, child, depth + 1, expanded, searchTokens)) {
117
+ if (flattenNode(childOutput, child, depth + 1, expanded, searchResultPaths)) {
118
descendantMatches = true;
119
}
120
}
@@ -189,13 +133,12 @@ function flattenNode(
133
export function flattenFileTree(input: {
134
readonly nodes: ReadonlyArray<FileTreeNode>;
135
readonly expanded: ReadonlySet<string>;
192
- readonly searchQuery?: string;
136
+ // Null restores normal directory expansion; an empty set is a search with no results.
137
+ readonly searchResultPaths?: ReadonlySet<string> | null;
138
}): ReadonlyArray<VisibleFileTreeNode> {
139
const output: VisibleFileTreeNode[] = [];
195
- const normalizedSearch = normalizeSearchQuery(input.searchQuery ?? "");
196
- const searchTokens = normalizedSearch.split(/[\s/\\._-]+/).filter(Boolean);
140
for (const node of input.nodes) {
198
- flattenNode(output, node, 0, input.expanded, searchTokens);
141
+ flattenNode(output, node, 0, input.expanded, input.searchResultPaths ?? null);
142
}
143
return output;
144
}
apps/mobile/src/features/files/thread-file-navigator-pane.tsx
+1
@@ -99,6 +99,7 @@ export function ThreadFileNavigatorPane(props: {
99
isPending={fileAccess.isPending || entriesQuery.isPending}
100
isRefreshing={entriesQuery.isRefreshing}
101
searchQuery={searchQuery}
102
+ searchResultPaths={entriesQuery.searchResultPaths}
103
searchTruncated={entriesQuery.searchTruncated}
104
selectedPath={props.selectedPath}
105
onPreviewFile={handlePreviewFile}
apps/mobile/src/features/files/useFileTreeEntries.ts
+9
-1
@@ -118,7 +118,14 @@ export function useFileTreeEntries(input: {
118
}
119
};
120
visit((rootData?.entries ?? []).filter((entry) => !entry.path.includes("/")));
121
- return { revision: entriesRevision, entries: [...merged.values()], reachableDirectories };
121
+ return {
122
+ revision: entriesRevision,
123
+ entries: [...merged.values()],
124
+ reachableDirectories,
125
+ searchResultPaths: searching
126
+ ? new Set((searchData?.entries ?? []).map((entry) => entry.path))
127
+ : null,
128
+ };
129
}, [directories, entriesRevision, rootData, searchData, searching]);
130
131
const refresh = useCallback(() => {
@@ -178,6 +185,7 @@ export function useFileTreeEntries(input: {
185
186
return {
187
entries: snapshot.entries,
188
+ searchResultPaths: snapshot.searchResultPaths,
189
isRefreshing: refreshingDirectories === directories,
190
error:
191
root.error ??