Skip to content

Commit 06b0873

Browse files
fix(mobile): tapping a ~/ file link now opens the file
Mobile rendered `~/` file links as tappable chips but never expanded the home prefix, so taps and the long-press menu did nothing. Expand it with the same shared helper web uses before routing. Fixes #18327 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent df78114 commit 06b0873

4 files changed

Lines changed: 33 additions & 13 deletions

File tree

‎apps/mobile/src/features/files/filePath.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
12
import {
23
isWorkspaceAudioPreviewPath,
34
isWorkspaceVideoPreviewPath,
@@ -68,6 +69,11 @@ function normalizeRelativePath(value: string): string | null {
6869
return segments.length > 0 ? segments.join("/") : null;
6970
}
7071

72+
/** `~/x` names a host file under the home inferred from the workspace root, as on web. */
73+
export function expandHomeFilePath(path: string, workspaceRoot: string | null | undefined): string {
74+
return workspaceRoot && path.startsWith("~/") ? resolvePathLinkTarget(path, workspaceRoot) : path;
75+
}
76+
7177
export function resolveWorkspaceRelativeFilePath(
7278
workspaceRoot: string | null | undefined,
7379
targetPath: string,

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ import { environmentThreadShells, threadEnvironment } from "../../state/threads"
211211
import { useAtomCommand } from "../../state/use-atom-command";
212212
import { useV2ItemSupport } from "../../state/v2-item-support";
213213
import {
214+
expandHomeFilePath,
214215
fileRoutePathSegments,
215216
isAbsolutePath,
216217
resolveWorkspaceRelativeFilePath,
@@ -1802,32 +1803,33 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
18021803
}
18031804

18041805
const presentation = resolveMarkdownLinkPresentation(href);
1805-
if (presentation.kind === "file") {
1806-
const relativePath = resolveWorkspaceRelativeFilePath(
1807-
props.workspaceRoot,
1808-
presentation.path,
1809-
);
1806+
const file =
1807+
presentation.kind === "file"
1808+
? { ...presentation, path: expandHomeFilePath(presentation.path, props.workspaceRoot) }
1809+
: null;
1810+
if (file) {
1811+
const relativePath = resolveWorkspaceRelativeFilePath(props.workspaceRoot, file.path);
18101812
if (relativePath) {
18111813
void Haptics.selectionAsync();
18121814
navigation.navigate("ThreadFile", {
18131815
environmentId: String(props.environmentId),
18141816
threadId: String(props.threadId),
18151817
path: fileRoutePathSegments(relativePath),
1816-
...(presentation.line ? { line: String(presentation.line) } : {}),
1818+
...(file.line ? { line: String(file.line) } : {}),
18171819
});
18181820
return;
18191821
}
18201822
}
18211823

18221824
// A host file outside the workspace, such as a report an agent wrote to
18231825
// a temp directory, opens read-only in the file screen.
1824-
if (presentation.kind === "file" && isAbsolutePath(presentation.path)) {
1826+
if (file && isAbsolutePath(file.path)) {
18251827
void Haptics.selectionAsync();
18261828
navigation.navigate("ThreadFile", {
18271829
environmentId: String(props.environmentId),
18281830
threadId: String(props.threadId),
1829-
path: fileRoutePathSegments(presentation.path),
1830-
...(presentation.line ? { line: String(presentation.line) } : {}),
1831+
path: fileRoutePathSegments(file.path),
1832+
...(file.line ? { line: String(file.line) } : {}),
18311833
});
18321834
return;
18331835
}

‎apps/mobile/src/features/threads/fileChipMenu.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ describe("resolveFileChipTarget", () => {
2121
expect(resolveFileChipTarget("src/app.ts", null)).toEqual({ relativePath: "src/app.ts" });
2222
});
2323

24+
it("resolves a home-relative link against the home holding the workspace", () => {
25+
expect(resolveFileChipTarget("~/.agents/AGENTS.md:4", "/Users/alice/repo")).toEqual({
26+
fullPath: "/Users/alice/.agents/AGENTS.md",
27+
});
28+
expect(resolveFileChipTarget("~/repo/src/app.ts", "/Users/alice/repo")).toEqual({
29+
fullPath: "/Users/alice/repo/src/app.ts",
30+
relativePath: "src/app.ts",
31+
});
32+
});
33+
2434
it("ignores links that are not files or cannot be opened", () => {
2535
expect(resolveFileChipTarget("https://example.com/app.ts", "/repo")).toBeNull();
2636
expect(resolveFileChipTarget("~/report.md", "/repo")).toBeNull();

‎apps/mobile/src/features/threads/fileChipMenu.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { MarkdownFileContextMenu } from "../../native/SelectableMarkdownTex
55
import { hostPreviewMimeTypeFromExtension } from "@t3tools/shared/filePreview";
66

77
import {
8+
expandHomeFilePath,
89
isAbsolutePath,
910
resolveWorkspaceFilePath,
1011
resolveWorkspaceRelativeFilePath,
@@ -19,16 +20,17 @@ export interface FileChipTarget {
1920
readonly relativePath?: string;
2021
}
2122

22-
/** Null when the link is not a file or resolves nowhere the feed can open, such as `~/x` or `../x`. */
23+
/** Null when the link is not a file or resolves nowhere the feed can open, such as `../x`. */
2324
export function resolveFileChipTarget(
2425
href: string,
2526
workspaceRoot: string | null | undefined,
2627
): FileChipTarget | null {
2728
const presentation = resolveMarkdownLinkPresentation(href);
2829
if (presentation.kind !== "file") return null;
29-
const relativePath = resolveWorkspaceRelativeFilePath(workspaceRoot, presentation.path);
30-
const fullPath = isAbsolutePath(presentation.path)
31-
? presentation.path
30+
const path = expandHomeFilePath(presentation.path, workspaceRoot);
31+
const relativePath = resolveWorkspaceRelativeFilePath(workspaceRoot, path);
32+
const fullPath = isAbsolutePath(path)
33+
? path
3234
: workspaceRoot && relativePath
3335
? resolveWorkspaceFilePath(workspaceRoot, relativePath)
3436
: undefined;

0 commit comments

Comments
 (0)