Skip to content
TypeScript

fix(web): Open in → Finder in the file preview opened the file in its default app instead of revealing it (#16955)

James Villarrubia3a78a2d15acb
diff --git a/apps/web/src/components/chat/OpenInPicker.browser.test.tsx b/apps/web/src/components/chat/OpenInPicker.browser.test.tsx
index 24ca6d27d03..6f418a2bbab 100644
--- a/apps/web/src/components/chat/OpenInPicker.browser.test.tsx
+++ b/apps/web/src/components/chat/OpenInPicker.browser.test.tsx
@@ -98,7 +98,11 @@ afterEach(async () => {
vi.unstubAllGlobals();
});
-async function renderPicker(availableEditors: readonly EditorId[] = editors, panel = false) {
+async function renderPicker(
+ availableEditors: readonly EditorId[] = editors,
+ panel = false,
+ { openInCwd = "/work/project", revealFileManager = false } = {},
+) {
await act(async () => {
for (const listener of state.listeners) listener();
const node = (
@@ -106,7 +110,8 @@ async function renderPicker(availableEditors: readonly EditorId[] = editors, pan
environmentId={selected}
keybindings={DEFAULT_RESOLVED_KEYBINDINGS}
availableEditors={availableEditors}
- openInCwd="/work/project"
+ openInCwd={openInCwd}
+ revealFileManager={revealFileManager}
displayMode={panel ? "panel" : "toolbar"}
compact={!panel}
/>
@@ -208,6 +213,19 @@ describe("host editor access", () => {
});
});
+it("reveals a file in the file manager instead of opening it", async () => {
+ state.allowed.add(selected);
+ await renderPicker(["file-manager"], false, {
+ openInCwd: "/work/project/README.md",
+ revealFileManager: true,
+ });
+ await click(primaryButton());
+ expect(state.run).toHaveBeenCalledExactlyOnceWith({
+ environmentId: selected,
+ input: { cwd: "/work/project/README.md", editor: "file-manager", reveal: true },
+ });
+});
+
describe("client editor links", () => {
it("opens an SSH editor URL without host operate permission", async () => {
state.remote = { mode: "remote-links", host: { kind: "ssh-alias", host: "test-host" } };
diff --git a/apps/web/src/components/chat/OpenInPicker.tsx b/apps/web/src/components/chat/OpenInPicker.tsx
index 98718ed9e28..c7fdf24f10e 100644
--- a/apps/web/src/components/chat/OpenInPicker.tsx
+++ b/apps/web/src/components/chat/OpenInPicker.tsx
@@ -212,6 +212,7 @@ export const OpenInPicker = memo(function OpenInPicker({
compact = false,
enableShortcut = true,
displayMode = "toolbar",
+ revealFileManager = false,
}: {
environmentId: EnvironmentId;
keybindings: ResolvedKeybindingsConfig;
@@ -221,6 +222,7 @@ export const OpenInPicker = memo(function OpenInPicker({
compact?: boolean;
enableShortcut?: boolean;
displayMode?: "toolbar" | "panel";
+ revealFileManager?: boolean;
}) {
const isPanel = displayMode === "panel";
const ActionGroup = isPanel ? "div" : Group;
@@ -266,6 +268,7 @@ export const OpenInPicker = memo(function OpenInPicker({
input: {
cwd: openInCwd,
editor,
+ ...(revealFileManager && editor === "file-manager" ? { reveal: true } : {}),
},
});
setPreferredEditor(editor);
diff --git a/apps/web/src/components/files/FilePreviewPanel.tsx b/apps/web/src/components/files/FilePreviewPanel.tsx
index fac7852f1e7..fbe58d50369 100644
--- a/apps/web/src/components/files/FilePreviewPanel.tsx
+++ b/apps/web/src/components/files/FilePreviewPanel.tsx
@@ -13,6 +13,7 @@ import {
isWorkspaceImagePreviewPath,
isWorkspaceVideoPreviewPath,
} from "@t3tools/shared/filePreview";
+import { useAtomValue } from "@effect/atom-react";
import {
DEFAULT_TOKENIZE_MAX_LENGTH,
VirtualizedFile,
@@ -67,6 +68,7 @@ import { assetEnvironment } from "~/state/assets";
import { usePreviewAvailable } from "~/browser/previewRuntime";
import { useEnvironmentHttpBaseUrl, usePrimaryEnvironmentId } from "~/state/environments";
import { previewEnvironment } from "~/state/preview";
+import { serverEnvironment } from "~/state/server";
import { useEnvironmentScope } from "~/state/session";
import { useAtomCommand } from "~/state/use-atom-command";
import { useAtomQueryRunner } from "~/state/use-atom-query-runner";
@@ -991,6 +993,7 @@ export default function FilePreviewPanel({
const canOperatePreview = useEnvironmentScope(environmentId, AuthPreviewOperateScope);
const primaryEnvironmentId = usePrimaryEnvironmentId();
const remoteOpenState = useRemoteOpenState(environmentId);
+ const serverConfig = useAtomValue(serverEnvironment.configValueAtom(environmentId));
const environmentHttpBaseUrl = useEnvironmentHttpBaseUrl(environmentId);
const previewAvailable = usePreviewAvailable(environmentId);
const createAssetUrl = useAtomQueryRunner(assetEnvironment.createUrl, {
@@ -1036,6 +1039,12 @@ export default function FilePreviewPanel({
attachment === undefined &&
(file.isNotFile || (folderTrail !== undefined && file.data === null && file.error === null));
const hostFolderPath = isFolder && isHostFile ? relativePath : null;
+ // A chat-linked folder reads as a file until its read settles, and revealing a
+ // folder selects it in its parent instead of opening it, so reveal waits.
+ const revealsInFileManager =
+ !isFolder &&
+ (file.data !== null || file.error !== null) &&
+ serverConfig?.shellRevealInFileManager === true;
// Everything preview-related keys off previewPath; a folder has no preview.
const previewPath = isFolder ? null : relativePath;
const [explorerOpen, setExplorerOpen] = useState(initialExplorerOpen);
@@ -1229,6 +1238,7 @@ export default function FilePreviewPanel({
availableEditors={availableEditors}
openInCwd={absolutePath}
compact
+ revealFileManager={revealsInFileManager}
/>
) : null}
{canToggleRendered && renderedMode ? (