@@ -16,6 +16,7 @@ import { getSyntaxHighlighterPromise } from "../lib/syntaxHighlighting";
1616import { GitHubIcon } from "./Icons" ;
1717import { Button } from "./ui/button" ;
1818import { setMarkdownTaskChecked } from "./files/filePreviewMode" ;
19+ import { readLocalApi } from "../localApi" ;
1920
2021vi . mock ( "../hooks/useFileMetadata" , ( ) => ( { useFileMetadata : ( ) => null } ) ) ;
2122vi . mock ( "@effect/atom-react" , ( ) => ( { useAtomValue : ( ) => null } ) ) ;
@@ -1046,6 +1047,105 @@ describe("ChatMarkdown Windows file links", () => {
10461047 } ) ;
10471048} ) ;
10481049
1050+ describe . each ( [ "Win32" , "MacIntel" ] ) (
1051+ "ChatMarkdown file path clipboard actions on %s" ,
1052+ ( platform ) => {
1053+ it . each ( [
1054+ {
1055+ name : "full Windows drive path with spaces" ,
1056+ cwd : "C:/Users/me/project" ,
1057+ href : "C:/Users/me/project/reports/Device Users.csv" ,
1058+ action : "copy-full" ,
1059+ expected : String . raw `C:\Users\me\project\reports\Device Users.csv` ,
1060+ } ,
1061+ {
1062+ name : "relative Windows drive path" ,
1063+ cwd : "C:/Users/me/project" ,
1064+ href : "C:/Users/me/project/reports/Device Users.csv" ,
1065+ action : "copy-relative" ,
1066+ expected : String . raw `project\reports\Device Users.csv` ,
1067+ } ,
1068+ {
1069+ name : "relative link in a Windows workspace" ,
1070+ cwd : String . raw `C:\Users\me\project` ,
1071+ href : "reports/Device Users.csv" ,
1072+ action : "copy-full" ,
1073+ expected : String . raw `C:\Users\me\project\reports\Device Users.csv` ,
1074+ } ,
1075+ {
1076+ name : "full UNC path" ,
1077+ cwd : String . raw `\\server\share\project` ,
1078+ href : "file://server/share/project/reports/Device%20Users.csv" ,
1079+ action : "copy-full" ,
1080+ expected : String . raw `\\server\share\project\reports\Device Users.csv` ,
1081+ } ,
1082+ {
1083+ name : "relative UNC path" ,
1084+ cwd : String . raw `\\server\share\project` ,
1085+ href : "file://server/share/project/reports/Device%20Users.csv" ,
1086+ action : "copy-relative" ,
1087+ expected : String . raw `project\reports\Device Users.csv` ,
1088+ } ,
1089+ {
1090+ name : "full POSIX path" ,
1091+ cwd : "/home/me/project" ,
1092+ href : "/home/me/project/reports/Device Users.csv" ,
1093+ action : "copy-full" ,
1094+ expected : "/home/me/project/reports/Device Users.csv" ,
1095+ } ,
1096+ {
1097+ name : "relative POSIX path" ,
1098+ cwd : "/home/me/project" ,
1099+ href : "/home/me/project/reports/Device Users.csv" ,
1100+ action : "copy-relative" ,
1101+ expected : "project/reports/Device Users.csv" ,
1102+ } ,
1103+ {
1104+ name : "Windows path with line and column" ,
1105+ cwd : "C:/Users/me/project" ,
1106+ href : "C:/Users/me/project/src/main.ts:12:3" ,
1107+ action : "copy-full" ,
1108+ expected : String . raw `C:\Users\me\project\src\main.ts:12:3` ,
1109+ } ,
1110+ ] ) ( "copies $name" , async ( { cwd, href, action, expected } ) => {
1111+ const writeText = vi . fn ( async ( _text : string ) => { } ) ;
1112+ const container = document . createElement ( "div" ) ;
1113+ document . body . append ( container ) ;
1114+ const root = createRoot ( container ) ;
1115+
1116+ try {
1117+ vi . stubGlobal ( "IS_REACT_ACT_ENVIRONMENT" , true ) ;
1118+ vi . stubGlobal ( "navigator" , { platform, clipboard : { writeText } } ) ;
1119+ const api = readLocalApi ( ) ;
1120+ if ( ! api ) throw new Error ( "Local API unavailable" ) ;
1121+ vi . spyOn ( api . contextMenu , "show" ) . mockResolvedValue ( action ) ;
1122+ await act ( async ( ) => {
1123+ root . render (
1124+ < ChatMarkdown
1125+ cwd = { cwd }
1126+ environmentId = { EnvironmentId . make ( "env-file-copy" ) }
1127+ text = { `[File](<${ href } >)` }
1128+ /> ,
1129+ ) ;
1130+ } ) ;
1131+ const link = container . querySelector ( ".chat-markdown-file-link" ) ;
1132+ if ( ! link ) throw new Error ( "File link unavailable" ) ;
1133+ await act ( async ( ) => {
1134+ link . dispatchEvent (
1135+ new MouseEvent ( "contextmenu" , { bubbles : true , clientX : 10 , clientY : 10 } ) ,
1136+ ) ;
1137+ } ) ;
1138+ expect ( writeText ) . toHaveBeenCalledWith ( expected ) ;
1139+ } finally {
1140+ await act ( async ( ) => root . unmount ( ) ) ;
1141+ container . remove ( ) ;
1142+ vi . unstubAllGlobals ( ) ;
1143+ vi . restoreAllMocks ( ) ;
1144+ }
1145+ } ) ;
1146+ } ,
1147+ ) ;
1148+
10491149it ( "opens a disclosure only when find selects a match inside it" , async ( ) => {
10501150 vi . stubGlobal ( "IS_REACT_ACT_ENVIRONMENT" , true ) ;
10511151 vi . stubGlobal (
0 commit comments