|
3 | 3 | buildFileLinkParentSuffixByPath, |
4 | 4 | fileLinkLabel, |
5 | 5 | resolvePathLinkTarget, |
| 6 | + splitFilePathPosition, |
6 | 7 | } from "@t3tools/shared/fileLinks"; |
7 | 8 | import { |
8 | 9 | isWindowsDrivePathHref, |
@@ -269,15 +270,20 @@ export function hasMarkdownFilePrimaryAction(input: { |
269 | 270 | export function markdownFileCopyMenuItems(input: { |
270 | 271 | targetPath: string; |
271 | 272 | workspaceRelativePath: string | null; |
272 | | - displayPath: string; |
273 | 273 | }) { |
| 274 | + const { path } = splitFilePathPosition(input.targetPath); |
| 275 | + const position = input.targetPath.slice(path.length); |
274 | 276 | 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 | + ]), |
281 | 287 | { |
282 | 288 | id: "copy-full", |
283 | 289 | label: "Copy full path", |
@@ -1180,8 +1186,8 @@ interface MarkdownFileLinkProps { |
1180 | 1186 | href: string; |
1181 | 1187 | targetPath: string; |
1182 | 1188 | iconPath: string; |
1183 | | - displayPath: string; |
1184 | 1189 | panelPath: string | null; |
| 1190 | + workspaceRelativePath: string | null; |
1185 | 1191 | line?: number | undefined; |
1186 | 1192 | label: string; |
1187 | 1193 | copyMarkdown: string; |
@@ -1885,8 +1891,8 @@ const MarkdownFileLink = memo(function MarkdownFileLink({ |
1885 | 1891 | href, |
1886 | 1892 | targetPath, |
1887 | 1893 | iconPath, |
1888 | | - displayPath, |
1889 | 1894 | panelPath, |
| 1895 | + workspaceRelativePath, |
1890 | 1896 | line, |
1891 | 1897 | label, |
1892 | 1898 | copyMarkdown, |
@@ -2074,7 +2080,6 @@ const MarkdownFileLink = memo(function MarkdownFileLink({ |
2074 | 2080 | const copyItems = markdownFileCopyMenuItems({ |
2075 | 2081 | targetPath, |
2076 | 2082 | workspaceRelativePath, |
2077 | | - displayPath, |
2078 | 2083 | }); |
2079 | 2084 | const clicked = await api.contextMenu.show( |
2080 | 2085 | [ |
@@ -2117,7 +2122,6 @@ const MarkdownFileLink = memo(function MarkdownFileLink({ |
2117 | 2122 | } |
2118 | 2123 | }, |
2119 | 2124 | [ |
2120 | | - displayPath, |
2121 | 2125 | handleCopy, |
2122 | 2126 | handleOpenInBrowser, |
2123 | 2127 | handleOpenInEditor, |
@@ -2236,8 +2240,8 @@ function areMarkdownFileLinkPropsEqual( |
2236 | 2240 | previous.targetPath === next.targetPath && |
2237 | 2241 | previous.iconPath === next.iconPath && |
2238 | 2242 | previous.environmentId === next.environmentId && |
2239 | | - previous.displayPath === next.displayPath && |
2240 | 2243 | previous.panelPath === next.panelPath && |
| 2244 | + previous.workspaceRelativePath === next.workspaceRelativePath && |
2241 | 2245 | previous.line === next.line && |
2242 | 2246 | previous.label === next.label && |
2243 | 2247 | previous.copyMarkdown === next.copyMarkdown && |
@@ -2604,8 +2608,8 @@ function useChatMarkdownState({ |
2604 | 2608 | href={fileLinkMeta.targetPath} |
2605 | 2609 | targetPath={fileLinkMeta.targetPath} |
2606 | 2610 | iconPath={fileLinkMeta.filePath} |
2607 | | - displayPath={fileLinkMeta.displayPath} |
2608 | 2611 | panelPath={panelPath} |
| 2612 | + workspaceRelativePath={fileLinkMeta.workspaceRelativePath} |
2609 | 2613 | line={fileLinkMeta.line} |
2610 | 2614 | label={fileLinkLabel( |
2611 | 2615 | { |
|
0 commit comments