Skip to content

Commit 662adcb

Browse files
Merge remote-tracking branch 'origin/main' into L79-18198
2 parents e5f5073 + b874ff6 commit 662adcb

21 files changed

Lines changed: 678 additions & 121 deletions

‎apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { formatFilePathForClipboard } from "@t3tools/client-runtime/media-actions";
2+
import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
13
import { resolveFilesystemReadAccess } from "@t3tools/client-runtime/state/filesystem";
24
import { environmentSession } from "../../state/session";
35
import { NativeStackScreenOptions } from "../../native/StackHeader";
@@ -783,7 +785,13 @@ export function ThreadFileScreen(props: ThreadFileRouteScreenProps) {
783785
title: "Copy path",
784786
icon: "doc.on.doc",
785787
inline: false,
786-
onPress: () => copyTextWithHaptic(relativePath),
788+
onPress: () =>
789+
copyTextWithHaptic(
790+
formatFilePathForClipboard(
791+
relativePath,
792+
resolvePathLinkTarget(relativePath, cwd ?? ""),
793+
),
794+
),
787795
} as const,
788796
]),
789797
fileData?.contents != null

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ import {
230230
} from "../files/filePath";
231231
import { waitForThreadShellReady } from "./threadForkNavigation";
232232
import { resolveUserMessageIntentBadge } from "./userMessageIntentBadge";
233-
import { fileChipMenu, resolveFileChipTarget, type FileChipAction } from "./fileChipMenu";
233+
import { fileChipClipboardPath, fileChipMenu, resolveFileChipTarget } from "./fileChipMenu";
234234
import { useFileChipShare } from "./useFileChipShare";
235235
import {
236236
MarkdownImageAvailableWidthContext,
@@ -1869,13 +1869,13 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
18691869
onFileContextMenuAction: (href, actionId) => {
18701870
const target = resolveFileChipTarget(href, props.workspaceRoot);
18711871
if (!target) return;
1872-
switch (actionId as FileChipAction) {
1872+
switch (actionId) {
18731873
case "copy-full-path":
1874-
if (target.fullPath) copyTextWithHaptic(target.fullPath);
1875-
return;
1876-
case "copy-relative-path":
1877-
if (target.relativePath) copyTextWithHaptic(target.relativePath);
1874+
case "copy-relative-path": {
1875+
const clipboardPath = fileChipClipboardPath(target, actionId);
1876+
if (clipboardPath !== undefined) copyTextWithHaptic(clipboardPath);
18781877
return;
1878+
}
18791879
case "open-file":
18801880
onMarkdownLinkPress(href);
18811881
return;

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
import { ThreadId } from "@t3tools/contracts";
22
import { describe, expect, it } from "vite-plus/test";
33

4-
import { fileChipMenu, fileChipShareSource, resolveFileChipTarget } from "./fileChipMenu";
4+
import {
5+
fileChipClipboardPath,
6+
fileChipMenu,
7+
fileChipShareSource,
8+
resolveFileChipTarget,
9+
} from "./fileChipMenu";
10+
11+
it("copies native paths from a relative file chip in a Windows workspace", () => {
12+
const target = resolveFileChipTarget("reports/Device Users.csv", "C:/repo");
13+
if (!target) throw new Error("File-chip target unavailable");
14+
expect(fileChipClipboardPath(target, "copy-full-path")).toBe(
15+
String.raw`C:\repo\reports\Device Users.csv`,
16+
);
17+
expect(fileChipClipboardPath(target, "copy-relative-path")).toBe(
18+
String.raw`reports\Device Users.csv`,
19+
);
20+
});
521

622
describe("resolveFileChipTarget", () => {
723
it("resolves a workspace-relative link to both paths", () => {

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { formatFilePathForClipboard } from "@t3tools/client-runtime/media-actions";
12
import { fileBasename } from "@t3tools/shared/path";
23
import type { ThreadId } from "@t3tools/contracts";
34
import { resolveMarkdownLinkPresentation } from "../../lib/markdownLinks";
@@ -10,13 +11,19 @@ import {
1011
resolveWorkspaceRelativeFilePath,
1112
} from "../files/filePath";
1213

13-
export type FileChipAction = "copy-full-path" | "copy-relative-path" | "open-file" | "save";
14-
1514
export interface FileChipTarget {
1615
readonly fullPath?: string;
1716
readonly relativePath?: string;
1817
}
1918

19+
export function fileChipClipboardPath(
20+
target: FileChipTarget,
21+
action: "copy-full-path" | "copy-relative-path",
22+
): string | undefined {
23+
const path = action === "copy-full-path" ? target.fullPath : target.relativePath;
24+
return path === undefined ? undefined : formatFilePathForClipboard(path, target.fullPath);
25+
}
26+
2027
export function resolveFileChipTarget(
2128
href: string,
2229
workspaceRoot: string | null | undefined,

‎apps/mobile/src/lib/mediaActions.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type AuthSessionState,
66
} from "@t3tools/contracts";
77
import { AsyncResult } from "effect/reactivity";
8+
import { mediaFileReference } from "@t3tools/client-runtime/media-reference";
89
import { beforeEach, expect, it, vi } from "vite-plus/test";
910

1011
const state = vi.hoisted(() => ({
@@ -96,6 +97,56 @@ beforeEach(() => {
9697
state.copy.mockReset();
9798
});
9899

100+
it.each([
101+
[
102+
"C:/repo/assets/shot.png",
103+
"C:/repo",
104+
String.raw`C:\repo\assets\shot.png`,
105+
String.raw`assets\shot.png`,
106+
],
107+
[
108+
String.raw`\\server\share\repo/assets/clip.mp4`,
109+
String.raw`\\server\share\repo`,
110+
String.raw`\\server\share\repo\assets\clip.mp4`,
111+
String.raw`assets\clip.mp4`,
112+
],
113+
] as const)("copies full and relative media paths for %s", (path, root, full, relative) => {
114+
const media = useMediaActions({
115+
environmentId,
116+
threadId,
117+
resource: { _tag: "media-file", threadId, path },
118+
reference: mediaFileReference(path, root),
119+
name: path.split(/[\\/]/).at(-1)!,
120+
mimeType: path.endsWith(".mp4") ? "video/mp4" : "image/png",
121+
});
122+
for (const [actionId, expected] of [
123+
["copy-full-path", full],
124+
["copy-relative-path", relative],
125+
] as const) {
126+
const action = media.actions.find(({ id }) => id === actionId);
127+
if (!action) throw new Error(`Missing media action: ${actionId}`);
128+
action.run();
129+
expect(state.copy).toHaveBeenLastCalledWith(expected);
130+
}
131+
expect(state.refresh).not.toHaveBeenCalled();
132+
expect(state.download).not.toHaveBeenCalled();
133+
});
134+
135+
it("preserves media URLs when copying", () => {
136+
const url = "https://cdn.test/assets/media?path=C:/repo/media";
137+
const media = useMediaActions({
138+
uri: url,
139+
name: "media",
140+
mimeType: "video/mp4",
141+
reference: { kind: "url", url },
142+
});
143+
const action = media.actions.find(({ id }) => id === "copy-url");
144+
if (!action) throw new Error("Copy URL action missing");
145+
action.run();
146+
expect(state.copy).toHaveBeenCalledWith(url);
147+
expect(state.refresh).not.toHaveBeenCalled();
148+
});
149+
99150
it.each(["workspace-file", "media-file"] as const)(
100151
"waits for the %s grant before enabling host menu actions",
101152
(_tag) => {

‎apps/mobile/src/state/mediaActions.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime
22
import * as Dialog from "../components/ui/Dialog";
33
import type { MediaActionsSource } from "../lib/mediaActionsSource";
44
import { useNavigation } from "@react-navigation/native";
5-
import type { MediaActionId } from "@t3tools/client-runtime/media-actions";
5+
import {
6+
formatFilePathForClipboard,
7+
type MediaActionId,
8+
} from "@t3tools/client-runtime/media-actions";
69
import {
710
AuthFilesystemReadScope,
811
type EnvironmentId,
@@ -108,16 +111,17 @@ export function useMediaActions(source: MediaActionsSource | undefined, onOpenFi
108111
{
109112
id: "copy-full-path" as const,
110113
title: "Copy full path",
111-
run: () => copyTextWithHaptic(reference.path),
114+
run: () => copyTextWithHaptic(formatFilePathForClipboard(reference.path)),
112115
},
113116
]
114117
: []),
115-
...(relativePath
118+
...(relativePath && reference?.kind === "file"
116119
? [
117120
{
118121
id: "copy-relative-path" as const,
119122
title: "Copy relative path",
120-
run: () => copyTextWithHaptic(relativePath),
123+
run: () =>
124+
copyTextWithHaptic(formatFilePathForClipboard(relativePath, reference.path)),
121125
},
122126
]
123127
: []),

‎apps/web/src/components/BranchToolbar.panel.browser.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ it.each([
132132
["local", null, "/tmp/project"],
133133
["worktree", null, null],
134134
["worktree", "/tmp/worktree", "/tmp/worktree"],
135+
["worktree", "C:/repo/worktree", String.raw`C:\repo\worktree`],
135136
] as const)(
136137
"copies only an existing workspace path with mode %s and worktree %s",
137138
async (envMode, worktreePath, copiedPath) => {

‎apps/web/src/components/BranchToolbar.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
2+
import { formatFilePathForClipboard } from "@t3tools/client-runtime/media-actions";
23
import { readLocalApi } from "../localApi";
34
import { stackedThreadToast, toastManager } from "./ui/toast";
45
import { ComposerContextLabel } from "./ComposerContextLabel";
@@ -118,13 +119,14 @@ function showWorkspaceContextMenu(event: ReactMouseEvent, workspacePath: string)
118119
})
119120
.then((action) => {
120121
if (action !== "copy-path") return;
121-
void writeTextToClipboard(workspacePath, "workspace path").then(
122+
const clipboardPath = formatFilePathForClipboard(workspacePath);
123+
void writeTextToClipboard(clipboardPath, "workspace path").then(
122124
(didCopy) => {
123125
if (didCopy) {
124126
toastManager.add({
125127
type: "success",
126128
title: "Path copied",
127-
description: workspacePath,
129+
description: clipboardPath,
128130
});
129131
}
130132
},

‎apps/web/src/components/ChatMarkdown.browser.test.tsx‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import "../index.css";
1111
import { useTheme } from "../hooks/useTheme";
1212
import { applyThemeColorPreview, getStandardThemeColors } from "../themePalette";
1313

14+
import { readLocalApi } from "../localApi";
15+
import { toastManager } from "./ui/toast";
1416
import { filesystemEnvironment } from "../state/filesystem";
1517
import { useRightPanelStore } from "../rightPanelStore";
1618
import { getSyntaxHighlighterPromise } from "../lib/syntaxHighlighting";
@@ -1262,6 +1264,60 @@ describe("ChatMarkdown thread find", () => {
12621264
);
12631265
});
12641266

1267+
it.each([
1268+
{
1269+
name: "Windows drive paths on a Mac client",
1270+
platform: "MacIntel",
1271+
cwd: "C:/repo",
1272+
href: "C:/repo/reports/Device Users.csv:12:3",
1273+
full: String.raw`C:\repo\reports\Device Users.csv:12:3`,
1274+
relative: String.raw`reports\Device Users.csv:12:3`,
1275+
},
1276+
{
1277+
name: "UNC paths on a Mac client",
1278+
platform: "MacIntel",
1279+
cwd: String.raw`\\server\share\repo`,
1280+
href: "file://server/share/repo/reports/report.csv",
1281+
full: String.raw`\\server\share\repo\reports\report.csv`,
1282+
relative: String.raw`reports\report.csv`,
1283+
},
1284+
{
1285+
name: "POSIX paths on a Windows client",
1286+
platform: "Win32",
1287+
cwd: "/home/repo",
1288+
href: "/home/repo/reports/report.csv",
1289+
full: "/home/repo/reports/report.csv",
1290+
relative: "reports/report.csv",
1291+
},
1292+
])("copies $name and shows the copied text", async ({ platform, cwd, href, full, relative }) => {
1293+
vi.spyOn(navigator, "platform", "get").mockReturnValue(platform);
1294+
vi.stubGlobal("ClipboardItem", undefined);
1295+
const writeText = vi.spyOn(navigator.clipboard, "writeText").mockResolvedValue(undefined);
1296+
const toast = vi.spyOn(toastManager, "add");
1297+
const api = readLocalApi();
1298+
if (!api) throw new Error("Local API unavailable");
1299+
const choose = vi.spyOn(api.contextMenu, "show");
1300+
const container = await renderText(`[File](<${href}>)`, {
1301+
cwd,
1302+
environmentId: EnvironmentId.make("env-file-copy"),
1303+
});
1304+
const link = container.querySelector(".chat-markdown-file-link");
1305+
if (!link) throw new Error("File link unavailable");
1306+
for (const [action, expected] of [
1307+
["copy-full", full],
1308+
["copy-relative", relative],
1309+
] as const) {
1310+
choose.mockResolvedValue(action);
1311+
await act(async () => {
1312+
link.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true }));
1313+
});
1314+
expect(writeText).toHaveBeenLastCalledWith(expected);
1315+
expect(toast).toHaveBeenLastCalledWith(
1316+
expect.objectContaining({ type: "success", description: expected }),
1317+
);
1318+
}
1319+
});
1320+
12651321
describe("ChatMarkdown math", () => {
12661322
const renderMath = async (
12671323
text: string,

‎apps/web/src/components/ChatMarkdown.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { formatFilePathForClipboard } from "@t3tools/client-runtime/media-actions";
12
import { MarkdownFindContext, findRevealRef } from "./chat/markdownFindContext";
23
import {
34
buildFileLinkParentSuffixByPath,
@@ -2119,7 +2120,7 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
21192120
return;
21202121
}
21212122

2122-
const value = resolveValue();
2123+
const value = resolveValue().then((text) => formatFilePathForClipboard(text, targetPath));
21232124
// Start the write before workspace lookup finishes so Safari retains the user gesture.
21242125
const write =
21252126
typeof navigator.clipboard.write === "function" && typeof ClipboardItem !== "undefined"

0 commit comments

Comments
 (0)