fix(web): open workspace root links in the file explorer (#12449)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Alex Southwellandgithub-actions[bot] authored and GitHub committed 2026-09-29 21:05:44 -03:00
1 parent 916ec94f93
commit 55ec55b1fb
10 files changed
+83 -3

No files matched your search

@@ -7,6 +7,7 @@ import {
} from "./fileCommentAnnotations";
import {
isMarkdownPreviewFile,
resolveFilePreviewPath,
setMarkdownTaskChecked,
shouldShowFileExplorer,
} from "./filePreviewMode";
@@ -120,3 +121,24 @@ describe("setMarkdownTaskChecked", () => {
expect(setMarkdownTaskChecked(markdown, 200, true)).toBe(markdown);
});
});
describe("resolveFilePreviewPath", () => {
it.each([
["/repo/project", null],
["/repo/project/", null],
[".", null],
[null, null],
["/repo/project/src", "/repo/project/src"],
["/repo/project/src/main.ts", "/repo/project/src/main.ts"],
["src/main.ts", "src/main.ts"],
["/repo/project-other", "/repo/project-other"],
])("opens %s in the appropriate workspace surface", (path, expected) => {
const relativePath = resolveFilePreviewPath(path, "/repo/project");
expect(relativePath).toBe(expected);
if (expected === null) {
expect(
shouldShowFileExplorer({ relativePath, explorerOpen: false, attachmentOpen: false }),
).toBe(true);
}
});
});
@@ -81,6 +81,7 @@ import { DiffCommentAnnotation } from "../diffs/DiffCommentAnnotation";
import { projectFileCacheKey, projectFileEditorCacheKey } from "./fileContentRevision";
import {
isMarkdownPreviewFile,
resolveFilePreviewPath,
setMarkdownTaskChecked,
shouldShowFileExplorer,
} from "./filePreviewMode";
@@ -907,7 +908,7 @@ export default function FilePreviewPanel({
environmentId,
cwd,
projectName,
relativePath,
relativePath: requestedPath,
attachment,
threadRef,
composerDraftTarget,
@@ -920,6 +921,8 @@ export default function FilePreviewPanel({
selectedFilePending,
workspaceMutationId,
}: FilePreviewPanelProps) {
const relativePath =
attachment === undefined ? resolveFilePreviewPath(requestedPath, cwd) : requestedPath;
const { resolvedTheme } = useTheme();
const wordWrap = useClientSettings((settings) => settings.wordWrap);
const primaryEnvironmentId = usePrimaryEnvironmentId();
@@ -945,7 +948,12 @@ export default function FilePreviewPanel({
// shown. The read still runs: a folder named `assets.png` is only knowable as a
// folder from the read failure, and the server stats before reading, so a folder
// costs an open and a stat and returns no body.
const file = useProjectFileQuery(environmentId, cwd, relativePath, attachment === undefined);
const file = useProjectFileQuery(
environmentId,
cwd,
relativePath,
attachment === undefined && relativePath !== null,
);
// A chat link cannot tell a folder from a file, so a folder arrives here as
// a file surface and the read fails. Keep the breadcrumbs, drop the preview
// pane, and let the tree fill the surface with the folder revealed. Mutation
@@ -1,5 +1,12 @@
import { workspaceRelativeFilePath } from "@t3tools/client-runtime/markdown-links";
import { isAbsolutePath } from "~/terminal-links";
/** Resolve workspace links before choosing between the explorer and a file preview. */
export function resolveFilePreviewPath(path: string | null, cwd: string): string | null {
if (path === null) return null;
return path === "." || workspaceRelativeFilePath(path, cwd) === "." ? null : path;
}
export const isMarkdownPreviewFile = (path: string): boolean => /\.(?:md|mdx)$/i.test(path);
export function shouldShowFileExplorer(input: {