Skip to content

Commit e3600f0

Browse files
mitchellmclaude
andcommitted
File menus: Open File, Open Parent Folder, fix preview/open-in-editor paths
Every file menu now offers the same OS actions from one helper (apps/web/src/fileOpenMenu.ts): "Open File" (default app) or "Open Folder", "Open Parent Folder" for files, then "Copy relative path" / "Copy full path". - Chat file chips: "Reveal in File Explorer" becomes Open File + Open Parent Folder. Preview media and Open in editor now resolve a bare filename through the workspace index, as reveal and the files panel already did, instead of joining it onto the workspace root (which named a file that does not exist). "Open in editor" is hidden when the preferred editor is the file manager. - Open-in picker (thread details card and the file preview header): the file manager entry reads "Open Folder" / "Open File" and an "Open Parent Folder" entry is added. - Changed-files card, diff panel and files tree: Open File / Open Folder, Open Parent Folder, Open with, Copy relative path, Copy full path. Folder rows in the changed-files card get a menu (they fell through to the native one). - Server: plain file-manager opens on Windows convert forward slashes to backslashes (Explorer opens Documents for `C:/a/b.png`) and drop a `:line[:col]` editor suffix. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 28bdec5 commit e3600f0

13 files changed

Lines changed: 574 additions & 197 deletions

‎apps/server/src/process/externalLauncher.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,45 @@ it.effect("reveals a file in File Explorer through PowerShell on Windows", () =>
342342
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
343343
);
344344

345+
it.effect("opens a file with Windows separators and no editor position on Windows", () =>
346+
Effect.gen(function* () {
347+
const fileSystem = yield* FileSystem.FileSystem;
348+
const path = yield* Path.Path;
349+
const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" });
350+
yield* fileSystem.writeFileString(path.join(binDir, "explorer.CMD"), "@echo off\r\n");
351+
352+
const spawnedCommands: ChildProcess.StandardCommand[] = [];
353+
yield* Effect.gen(function* () {
354+
const launcher = yield* ExternalLauncher.ExternalLauncher;
355+
// Web file links arrive with forward slashes, and Explorer opens the
356+
// Documents folder for a path it cannot parse.
357+
yield* launcher.launchEditor({
358+
editor: "file-manager",
359+
cwd: "C:/workspace with spaces/media/thumb.png",
360+
});
361+
yield* launcher.launchEditor({
362+
editor: "file-manager",
363+
cwd: "C:/workspace/src/index.ts:12:4",
364+
});
365+
}).pipe(
366+
Effect.provide(
367+
layerTest({
368+
platform: "win32",
369+
env: { PATH: binDir, PATHEXT: ".COM;.EXE;.BAT;.CMD" },
370+
onSpawn: (command) => {
371+
spawnedCommands.push(command);
372+
},
373+
}),
374+
),
375+
);
376+
377+
assert.deepEqual(
378+
spawnedCommands.map((command) => command.args),
379+
[["C:\\workspace with spaces\\media\\thumb.png"], ["C:\\workspace\\src\\index.ts"]],
380+
);
381+
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
382+
);
383+
345384
// Real-chain smoke check for the Explorer selection contract: runs the exact
346385
// PowerShell source the reveal launch encodes, against a stub that records
347386
// the raw argument tail it receives, and asserts a spaced path arrives as the

‎apps/server/src/process/externalLauncher.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,17 +560,30 @@ const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
560560
return yield* resolveFileManagerRevealLaunch(input.cwd, platform, env, command);
561561
}
562562

563+
const target = fileManagerOpenTarget(input.cwd);
563564
return {
564565
editor: editorDef.id,
565566
target: input.cwd,
566567
command,
567568
args:
568569
command === "explorer.exe" && env.WSL_DISTRO_NAME !== undefined
569-
? [resolveWslFileManagerPath(input.cwd, env.WSL_DISTRO_NAME)]
570-
: [input.cwd],
570+
? [resolveWslFileManagerPath(target, env.WSL_DISTRO_NAME)]
571+
: [platform === "win32" ? normalizeWindowsFileManagerPath(target) : target],
571572
};
572573
});
573574

575+
/**
576+
* The path a plain file-manager open hands to the OS. Editor links carry a
577+
* `:line[:column]` suffix that names no file on disk, so it is dropped here.
578+
* Opening a file this way launches its default app; opening a folder shows it.
579+
*/
580+
function fileManagerOpenTarget(target: string): string {
581+
return Option.match(parseTargetPathAndPosition(target), {
582+
onNone: () => target,
583+
onSome: ({ path }) => path,
584+
});
585+
}
586+
574587
/**
575588
* PowerShell source that launches File Explorer with its raw selection
576589
* switch. Explorer's contract is the single argument `/select,"<path>"` with
@@ -605,6 +618,8 @@ function fileExplorerRevealLaunch(
605618
};
606619
}
607620

621+
// Explorer does not understand forward slashes: given `C:/a/b.png` it opens
622+
// the user's Documents folder instead of the file.
608623
function normalizeWindowsFileManagerPath(target: string): string {
609624
return target.replaceAll("/", "\\");
610625
}

0 commit comments

Comments
 (0)