33 buildFileLinkParentSuffixByPath ,
44 fileLinkLabel ,
55 resolvePathLinkTarget ,
6+ splitFilePathPosition ,
67} from "@t3tools/shared/fileLinks" ;
78import {
89 isWindowsDrivePathHref ,
@@ -272,6 +273,25 @@ function hasMarkdownFilePrimaryAction(input: {
272273 ) ;
273274}
274275
276+ export function markdownFileCopyMenuItems ( {
277+ targetPath,
278+ workspaceRelativePath,
279+ } : Pick < MarkdownFileLinkMeta , "targetPath" | "workspaceRelativePath" > ) {
280+ const items = [
281+ { id : "copy-full" , label : "Copy full path" , value : targetPath , title : "Full path" } ,
282+ ] ;
283+ if ( workspaceRelativePath !== null ) {
284+ const position = targetPath . slice ( splitFilePathPosition ( targetPath ) . path . length ) ;
285+ items . unshift ( {
286+ id : "copy-relative" ,
287+ label : "Copy relative path" ,
288+ value : `${ workspaceRelativePath } ${ position } ` ,
289+ title : "Relative path" ,
290+ } ) ;
291+ }
292+ return items ;
293+ }
294+
275295export function shouldUseMarkdownFileBrowserPrimaryAction ( input : {
276296 iconPath : string ;
277297 canOpenInEditor : boolean ;
@@ -1201,7 +1221,7 @@ interface MarkdownFileLinkProps {
12011221 href : string ;
12021222 targetPath : string ;
12031223 iconPath : string ;
1204- displayPath : string ;
1224+ workspaceRelativePath : string | null ;
12051225 panelPath : string | null ;
12061226 line ?: number | undefined ;
12071227 label : string ;
@@ -1902,7 +1922,7 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
19021922 href,
19031923 targetPath,
19041924 iconPath,
1905- displayPath ,
1925+ workspaceRelativePath ,
19061926 panelPath,
19071927 line,
19081928 label,
@@ -2084,6 +2104,7 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
20842104 if ( ! api ) return ;
20852105
20862106 try {
2107+ const copyItems = markdownFileCopyMenuItems ( { targetPath, workspaceRelativePath } ) ;
20872108 const clicked = await api . contextMenu . show (
20882109 [
20892110 ...( onOpenMedia ? ( [ { id : "preview-media" , label : "Preview media" } ] as const ) : [ ] ) ,
@@ -2092,8 +2113,7 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
20922113 ? ( [ { id : "open-in-browser" , label : "Open in integrated browser" } ] as const )
20932114 : [ ] ) ,
20942115 ...( onReveal && revealLabel ? ( [ { id : "reveal" , label : revealLabel } ] as const ) : [ ] ) ,
2095- { id : "copy-relative" , label : "Copy relative path" } ,
2096- { id : "copy-full" , label : "Copy full path" } ,
2116+ ...copyItems . map ( ( { id, label } ) => ( { id, label } ) ) ,
20972117 ] as const ,
20982118 position ,
20992119 ) ;
@@ -2114,12 +2134,9 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
21142134 handleRevealInFileManager ( ) ;
21152135 return ;
21162136 }
2117- if ( clicked === "copy-relative" ) {
2118- handleCopy ( displayPath , "Relative path" ) ;
2119- return ;
2120- }
2121- if ( clicked === "copy-full" ) {
2122- handleCopy ( targetPath , "Full path" ) ;
2137+ const copyItem = copyItems . find ( ( { id } ) => id === clicked ) ;
2138+ if ( copyItem ) {
2139+ handleCopy ( copyItem . value , copyItem . title ) ;
21232140 }
21242141 } catch ( cause ) {
21252142 reportMarkdownActionFailure (
@@ -2229,7 +2246,7 @@ function areMarkdownFileLinkPropsEqual(
22292246 previous . targetPath === next . targetPath &&
22302247 previous . iconPath === next . iconPath &&
22312248 previous . environmentId === next . environmentId &&
2232- previous . displayPath === next . displayPath &&
2249+ previous . workspaceRelativePath === next . workspaceRelativePath &&
22332250 previous . panelPath === next . panelPath &&
22342251 previous . line === next . line &&
22352252 previous . label === next . label &&
@@ -2636,7 +2653,7 @@ function useChatMarkdownState({
26362653 href = { fileLinkMeta . targetPath }
26372654 targetPath = { fileLinkMeta . targetPath }
26382655 iconPath = { fileLinkMeta . filePath }
2639- displayPath = { fileLinkMeta . displayPath }
2656+ workspaceRelativePath = { fileLinkMeta . workspaceRelativePath }
26402657 panelPath = { panelPath }
26412658 line = { fileLinkMeta . line }
26422659 label = { fileLinkLabel (
0 commit comments