The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 21:00 UTC
fix(web): Cmd+A in the rendered Markdown preview selects only the file (#30738)
Julius Marminge committed
Nov 11, 2026 at 16:28 UTC
1c65ad032ebc826b71f4d43e733df01de1419d2f
2 files changed
+58
-6
apps/web/src/components/files/FilePreviewPanel.browser.test.tsx
+29
-3
@@ -121,11 +121,11 @@ function setup() {
121
};
122
}
123
124
-function markdownPreview(truncated: boolean) {
124
+function markdownPreview(truncated: boolean, contents = "- [ ] Keep the rest of this file\n") {
125
state.file = {
126
relativePath: "tasks.md",
127
- contents: "- [ ] Keep the rest of this file\n",
128
- byteLength: truncated ? 1_200_000 : 32,
127
+ contents,
128
+ byteLength: truncated ? 1_200_000 : contents.length,
129
truncated,
130
};
131
return filePreview("tasks.md");
@@ -278,3 +278,29 @@ describe("rendered Markdown task saves", () => {
278
});
279
});
280
});
281
+
282
+describe("rendered Markdown select all", () => {
283
+ it("selects only the rendered file, including after a task toggle", async () => {
284
+ using _settings = setup();
285
+ await using screen = await render(
286
+ <>
287
+ <p>Transcript text from the chat thread.</p>
288
+ {markdownPreview(false, "- [ ] Task item\n\nRendered file body.\n")}
289
+ </>,
290
+ );
291
+ const expectFileOnlySelection = async () => {
292
+ await userEvent.keyboard(
293
+ isMacPlatform(navigator.platform) ? "{Meta>}a{/Meta}" : "{Control>}a{/Control}",
294
+ );
295
+ const selection = window.getSelection()?.toString() ?? "";
296
+ expect(selection).toContain("Rendered file body.");
297
+ expect(selection).not.toContain("Transcript text from the chat thread.");
298
+ };
299
+
300
+ await userEvent.click(screen.getByText("Rendered file body."));
301
+ await expectFileOnlySelection();
302
+ // A toggled checkbox keeps focus on an input inside the preview.
303
+ await userEvent.click(screen.getByRole("checkbox"));
304
+ await expectFileOnlySelection();
305
+ });
306
+});
apps/web/src/components/files/FilePreviewPanel.tsx
+29
-3
@@ -47,7 +47,14 @@ import {
47
import { mediaFileReference } from "@t3tools/client-runtime/media-reference";
48
import { FolderTree, Globe2, WrapTextIcon } from "lucide-react";
49
import * as Schema from "effect/Schema";
50
-import { lazy, Suspense, useEffect, useRef, useState } from "react";
50
+import {
51
+ lazy,
52
+ Suspense,
53
+ useEffect,
54
+ useRef,
55
+ useState,
56
+ type KeyboardEvent as ReactKeyboardEvent,
57
+} from "react";
58
59
import { isBrowserPreviewFile, openFileInPreview } from "~/browser/openFileInPreview";
60
import { useAssetUrlRefresh, useAssetUrlState } from "~/assets/assetUrls";
@@ -61,7 +68,7 @@ import { useStableCallback } from "~/hooks/useStableCallback";
68
import { getLocalStorageItem, setLocalStorageItem, useLocalStorage } from "~/hooks/useLocalStorage";
69
import { resolveDiffThemeName } from "~/lib/diffRendering";
70
import { PREFERRED_HIGHLIGHTER } from "~/lib/syntaxHighlighting";
64
-import { cn } from "~/lib/utils";
71
+import { cn, isMacPlatform } from "~/lib/utils";
72
import { requestWorkspaceFocus } from "~/lib/workspaceFocus";
73
import type { ChatFileAttachment } from "~/types";
74
import { isHostPath } from "@t3tools/shared/path";
@@ -933,6 +940,25 @@ function EditableFileSurface({
940
);
941
}
942
943
+function selectRenderedContentOnSelectAll(event: ReactKeyboardEvent<HTMLElement>) {
944
+ const mac = isMacPlatform(navigator.platform);
945
+ const selectAll =
946
+ event.key.toLowerCase() === "a" &&
947
+ (mac ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey) &&
948
+ !event.shiftKey &&
949
+ !event.altKey;
950
+ // React bubbles keys from portaled children (the image dialog) through this surface.
951
+ if (
952
+ !selectAll ||
953
+ !(event.target instanceof Node) ||
954
+ !event.currentTarget.contains(event.target)
955
+ ) {
956
+ return;
957
+ }
958
+ event.preventDefault();
959
+ window.getSelection()?.selectAllChildren(event.currentTarget);
960
+}
961
+
962
function RenderedMarkdownSurface({
963
environmentId,
964
cwd,
@@ -960,7 +986,7 @@ function RenderedMarkdownSurface({
986
useFileSaveSession(saveTarget, onPendingChange);
987
988
return (
963
- <ScrollArea className="min-h-0 flex-1">
989
+ <ScrollArea className="min-h-0 flex-1" onKeyDown={selectRenderedContentOnSelectAll}>
990
<FileMarkdownPreview
991
text={contents}
992
cwd={cwd}