Skip to content

Commit aba81de

Browse files
fix(web): copy file paths relative to the thread workspace
1 parent 834999b commit aba81de

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
buildFileLinkParentSuffixByPath,
44
fileLinkLabel,
55
resolvePathLinkTarget,
6+
splitFilePathPosition,
67
} from "@t3tools/shared/fileLinks";
78
import {
89
isWindowsDrivePathHref,
@@ -269,15 +270,20 @@ export function hasMarkdownFilePrimaryAction(input: {
269270
export function markdownFileCopyMenuItems(input: {
270271
targetPath: string;
271272
workspaceRelativePath: string | null;
272-
displayPath: string;
273273
}) {
274+
const { path } = splitFilePathPosition(input.targetPath);
275+
const position = input.targetPath.slice(path.length);
274276
return [
275-
{
276-
id: "copy-relative",
277-
label: "Copy relative path",
278-
value: input.displayPath,
279-
title: "Relative path",
280-
},
277+
...(input.workspaceRelativePath === null
278+
? []
279+
: [
280+
{
281+
id: "copy-relative",
282+
label: "Copy relative path",
283+
value: `${input.workspaceRelativePath}${position}`,
284+
title: "Relative path",
285+
} as const,
286+
]),
281287
{
282288
id: "copy-full",
283289
label: "Copy full path",
@@ -1180,8 +1186,8 @@ interface MarkdownFileLinkProps {
11801186
href: string;
11811187
targetPath: string;
11821188
iconPath: string;
1183-
displayPath: string;
11841189
panelPath: string | null;
1190+
workspaceRelativePath: string | null;
11851191
line?: number | undefined;
11861192
label: string;
11871193
copyMarkdown: string;
@@ -1885,8 +1891,8 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
18851891
href,
18861892
targetPath,
18871893
iconPath,
1888-
displayPath,
18891894
panelPath,
1895+
workspaceRelativePath,
18901896
line,
18911897
label,
18921898
copyMarkdown,
@@ -2074,7 +2080,6 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
20742080
const copyItems = markdownFileCopyMenuItems({
20752081
targetPath,
20762082
workspaceRelativePath,
2077-
displayPath,
20782083
});
20792084
const clicked = await api.contextMenu.show(
20802085
[
@@ -2117,7 +2122,6 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
21172122
}
21182123
},
21192124
[
2120-
displayPath,
21212125
handleCopy,
21222126
handleOpenInBrowser,
21232127
handleOpenInEditor,
@@ -2236,8 +2240,8 @@ function areMarkdownFileLinkPropsEqual(
22362240
previous.targetPath === next.targetPath &&
22372241
previous.iconPath === next.iconPath &&
22382242
previous.environmentId === next.environmentId &&
2239-
previous.displayPath === next.displayPath &&
22402243
previous.panelPath === next.panelPath &&
2244+
previous.workspaceRelativePath === next.workspaceRelativePath &&
22412245
previous.line === next.line &&
22422246
previous.label === next.label &&
22432247
previous.copyMarkdown === next.copyMarkdown &&
@@ -2604,8 +2608,8 @@ function useChatMarkdownState({
26042608
href={fileLinkMeta.targetPath}
26052609
targetPath={fileLinkMeta.targetPath}
26062610
iconPath={fileLinkMeta.filePath}
2607-
displayPath={fileLinkMeta.displayPath}
26082611
panelPath={panelPath}
2612+
workspaceRelativePath={fileLinkMeta.workspaceRelativePath}
26092613
line={fileLinkMeta.line}
26102614
label={fileLinkLabel(
26112615
{

‎docs/user/file-links.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# File links in messages
2+
3+
On web and desktop, right-click a file link in a message to copy its path.
4+
**Copy full path** copies the resolved path on the connected environment.
5+
**Copy relative path** appears when a workspace-relative path is available and
6+
copies that path without the workspace folder's name. Links with a line or
7+
column keep that position in either copied value.
8+
9+
Relative links use the thread's worktree folder, or the project folder when the
10+
thread has no worktree. They do not follow directory changes made by an agent's
11+
commands. Absolute links to files elsewhere, such as a temporary report outside
12+
the project, offer **Copy full path**.

0 commit comments

Comments
 (0)