Skip to content

Commit d7abbe1

Browse files
fix(web): Open in → Finder in the file preview reveals the file instead of opening it
The file preview passed the file's path to the Open in menu, which sent it to the file manager without `reveal`, so macOS `open <file>` launched the file's default app. The preview now sets `revealFileManager` when the server config has `shellRevealInFileManager`, and the menu then sends `reveal: true`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 4ce6a51 commit d7abbe1

3 files changed

Lines changed: 55 additions & 3 deletions

File tree

‎apps/web/src/components/chat/OpenInPicker.test.tsx‎

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,25 @@ afterEach(async () => {
128128
vi.unstubAllGlobals();
129129
});
130130

131-
async function renderPicker() {
131+
async function renderPicker(
132+
props: {
133+
availableEditors?: readonly EditorId[];
134+
openInCwd?: string;
135+
revealFileManager?: boolean;
136+
} = {},
137+
) {
132138
await act(async () => {
133139
for (const listener of state.listeners) listener();
134140
const node = (
135141
<OpenInPicker
136142
environmentId={selected}
137143
keybindings={DEFAULT_RESOLVED_KEYBINDINGS}
138-
availableEditors={editors}
139-
openInCwd="/work/project"
144+
availableEditors={props.availableEditors ?? editors}
145+
openInCwd={props.openInCwd ?? "/work/project"}
140146
compact
147+
{...(props.revealFileManager === undefined
148+
? {}
149+
: { revealFileManager: props.revealFileManager })}
141150
/>
142151
);
143152
if (renderer) renderer.update(node);
@@ -197,6 +206,38 @@ describe("host editor access", () => {
197206
});
198207
});
199208

209+
describe("file manager targets", () => {
210+
async function chooseFileManager(revealFileManager: boolean) {
211+
state.allowed.add(selected);
212+
vi.stubGlobal("navigator", { platform: "MacIntel" });
213+
await renderPicker({
214+
availableEditors: ["vscode", "file-manager"],
215+
openInCwd: "/work/project/src/index.ts",
216+
revealFileManager,
217+
});
218+
const finder = renderer!.root
219+
.findAll((node) => node.type === "button" && node.props.disabled === false)
220+
.find((node) => node.findAll((child) => child.children.includes("Finder")).length > 0)!;
221+
await act(async () => finder.props.onClick());
222+
}
223+
224+
it("reveals a file in the file manager instead of opening it with its default app", async () => {
225+
await chooseFileManager(true);
226+
expect(state.run).toHaveBeenCalledExactlyOnceWith({
227+
environmentId: selected,
228+
input: { cwd: "/work/project/src/index.ts", editor: "file-manager", reveal: true },
229+
});
230+
});
231+
232+
it("opens the target directly when the server cannot reveal", async () => {
233+
await chooseFileManager(false);
234+
expect(state.run).toHaveBeenCalledExactlyOnceWith({
235+
environmentId: selected,
236+
input: { cwd: "/work/project/src/index.ts", editor: "file-manager" },
237+
});
238+
});
239+
});
240+
200241
describe("client editor links", () => {
201242
it("opens an SSH editor URL without host operate permission", async () => {
202243
state.remote = { mode: "remote-links", host: { kind: "ssh-alias", host: "test-host" } };

‎apps/web/src/components/chat/OpenInPicker.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export const OpenInPicker = memo(function OpenInPicker({
211211
compact = false,
212212
enableShortcut = true,
213213
displayMode = "toolbar",
214+
revealFileManager = false,
214215
}: {
215216
environmentId: EnvironmentId;
216217
keybindings: ResolvedKeybindingsConfig;
@@ -220,6 +221,10 @@ export const OpenInPicker = memo(function OpenInPicker({
220221
compact?: boolean;
221222
enableShortcut?: boolean;
222223
displayMode?: "toolbar" | "panel";
224+
/** `openInCwd` is a file: the file manager selects it instead of handing it
225+
to its default app. Pass only when the server sets
226+
`shellRevealInFileManager`. */
227+
revealFileManager?: boolean;
223228
}) {
224229
const isPanel = displayMode === "panel";
225230
const ActionGroup = isPanel ? "div" : Group;
@@ -271,6 +276,7 @@ export const OpenInPicker = memo(function OpenInPicker({
271276
input: {
272277
cwd: openInCwd,
273278
editor,
279+
...(revealFileManager && editor === "file-manager" ? { reveal: true } : {}),
274280
},
275281
});
276282
setPreferredEditor(editor);
@@ -283,6 +289,7 @@ export const OpenInPicker = memo(function OpenInPicker({
283289
openInEditorMutation,
284290
preferredEditor,
285291
remote,
292+
revealFileManager,
286293
setPreferredEditor,
287294
],
288295
);

‎apps/web/src/components/files/FilePreviewPanel.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
isAtomCommandInterrupted,
3737
squashAtomCommandFailure,
3838
} from "@t3tools/client-runtime/state/runtime";
39+
import { useAtomValue } from "@effect/atom-react";
3940
import { mediaFileReference } from "@t3tools/client-runtime/media-reference";
4041
import { FolderTree, Globe2, WrapTextIcon } from "lucide-react";
4142
import { Code2, Eye, Table2 } from "lucide";
@@ -66,6 +67,7 @@ import { assetEnvironment } from "~/state/assets";
6667
import { usePreviewAvailable } from "~/browser/previewRuntime";
6768
import { useEnvironmentHttpBaseUrl, usePrimaryEnvironmentId } from "~/state/environments";
6869
import { previewEnvironment } from "~/state/preview";
70+
import { serverEnvironment } from "~/state/server";
6971
import { useEnvironmentScope } from "~/state/session";
7072
import { useAtomCommand } from "~/state/use-atom-command";
7173
import { useAtomQueryRunner } from "~/state/use-atom-query-runner";
@@ -1025,6 +1027,7 @@ export default function FilePreviewPanel({
10251027
const canOperatePreview = useEnvironmentScope(environmentId, AuthPreviewOperateScope);
10261028
const primaryEnvironmentId = usePrimaryEnvironmentId();
10271029
const remoteOpenState = useRemoteOpenState(environmentId);
1030+
const serverConfig = useAtomValue(serverEnvironment.configValueAtom(environmentId));
10281031
const environmentHttpBaseUrl = useEnvironmentHttpBaseUrl(environmentId);
10291032
const previewAvailable = usePreviewAvailable(environmentId);
10301033
const createAssetUrl = useAtomQueryRunner(assetEnvironment.createUrl, {
@@ -1253,6 +1256,7 @@ export default function FilePreviewPanel({
12531256
availableEditors={availableEditors}
12541257
openInCwd={absolutePath}
12551258
compact
1259+
revealFileManager={serverConfig?.shellRevealInFileManager === true}
12561260
/>
12571261
) : null}
12581262
{canToggleRendered && renderedMode ? (

0 commit comments

Comments
 (0)