33 buildFileLinkParentSuffixByPath ,
44 fileLinkLabel ,
55 resolvePathLinkTarget ,
6+ splitFilePathPosition ,
67} from "@t3tools/shared/fileLinks" ;
78import {
89 isWindowsDrivePathHref ,
@@ -277,6 +278,25 @@ function hasMarkdownFilePrimaryAction(input: {
277278 ) ;
278279}
279280
281+ export function markdownFileCopyMenuItems ( {
282+ targetPath,
283+ workspaceRelativePath,
284+ } : Pick < MarkdownFileLinkMeta , "targetPath" | "workspaceRelativePath" > ) {
285+ const items = [
286+ { id : "copy-full" , label : "Copy full path" , value : targetPath , title : "Full path" } ,
287+ ] ;
288+ if ( workspaceRelativePath !== null ) {
289+ const position = targetPath . slice ( splitFilePathPosition ( targetPath ) . path . length ) ;
290+ items . unshift ( {
291+ id : "copy-relative" ,
292+ label : "Copy relative path" ,
293+ value : `${ workspaceRelativePath } ${ position } ` ,
294+ title : "Relative path" ,
295+ } ) ;
296+ }
297+ return items ;
298+ }
299+
280300export function shouldUseMarkdownFileBrowserPrimaryAction ( input : {
281301 iconPath : string ;
282302 canOpenInEditor : boolean ;
@@ -1213,7 +1233,7 @@ interface MarkdownFileLinkProps {
12131233 href : string ;
12141234 targetPath : string ;
12151235 iconPath : string ;
1216- displayPath : string ;
1236+ workspaceRelativePath : string | null ;
12171237 panelPath : string | null ;
12181238 line ?: number | undefined ;
12191239 label : string ;
@@ -1950,7 +1970,7 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
19501970 href,
19511971 targetPath,
19521972 iconPath,
1953- displayPath ,
1973+ workspaceRelativePath ,
19541974 panelPath,
19551975 line,
19561976 label,
@@ -2132,6 +2152,7 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
21322152 if ( ! api ) return ;
21332153
21342154 try {
2155+ const copyItems = markdownFileCopyMenuItems ( { targetPath, workspaceRelativePath } ) ;
21352156 const clicked = await api . contextMenu . show (
21362157 [
21372158 ...( onOpenMedia ? ( [ { id : "preview-media" , label : "Preview media" } ] as const ) : [ ] ) ,
@@ -2140,8 +2161,7 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
21402161 ? ( [ { id : "open-in-browser" , label : "Open in integrated browser" } ] as const )
21412162 : [ ] ) ,
21422163 ...( onReveal && revealLabel ? ( [ { id : "reveal" , label : revealLabel } ] as const ) : [ ] ) ,
2143- { id : "copy-relative" , label : "Copy relative path" } ,
2144- { id : "copy-full" , label : "Copy full path" } ,
2164+ ...copyItems . map ( ( { id, label } ) => ( { id, label } ) ) ,
21452165 ] as const ,
21462166 position ,
21472167 ) ;
@@ -2162,12 +2182,9 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
21622182 handleRevealInFileManager ( ) ;
21632183 return ;
21642184 }
2165- if ( clicked === "copy-relative" ) {
2166- handleCopy ( displayPath , "Relative path" ) ;
2167- return ;
2168- }
2169- if ( clicked === "copy-full" ) {
2170- handleCopy ( targetPath , "Full path" ) ;
2185+ const copyItem = copyItems . find ( ( { id } ) => id === clicked ) ;
2186+ if ( copyItem ) {
2187+ handleCopy ( copyItem . value , copyItem . title ) ;
21712188 }
21722189 } catch ( cause ) {
21732190 reportMarkdownActionFailure (
@@ -2277,7 +2294,7 @@ function areMarkdownFileLinkPropsEqual(
22772294 previous . targetPath === next . targetPath &&
22782295 previous . iconPath === next . iconPath &&
22792296 previous . environmentId === next . environmentId &&
2280- previous . displayPath === next . displayPath &&
2297+ previous . workspaceRelativePath === next . workspaceRelativePath &&
22812298 previous . panelPath === next . panelPath &&
22822299 previous . line === next . line &&
22832300 previous . label === next . label &&
@@ -2708,7 +2725,7 @@ function useChatMarkdownState({
27082725 href = { fileLinkMeta . targetPath }
27092726 targetPath = { fileLinkMeta . targetPath }
27102727 iconPath = { fileLinkMeta . filePath }
2711- displayPath = { fileLinkMeta . displayPath }
2728+ workspaceRelativePath = { fileLinkMeta . workspaceRelativePath }
27122729 panelPath = { panelPath }
27132730 line = { fileLinkMeta . line }
27142731 label = { fileLinkLabel (
0 commit comments