Skip to content

Commit b24c06e

Browse files
fix(web): Cmd+A in the rendered Markdown preview selects only the file
Pressing the select-all chord inside the Files panel's rendered Markdown preview selected the whole app, because nothing handled the key there. The rendered surface now scopes select-all to its own content and leaves editable descendants to their default. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0b0ee94 commit b24c06e

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ import { mediaFileReference } from "@t3tools/client-runtime/media-reference";
4747
import { FolderTree, Globe2, WrapTextIcon } from "lucide-react";
4848
import { Code2, Eye, Table2 } from "lucide";
4949
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";
5158

5259
import { isBrowserPreviewFile, openFileInPreview } from "~/browser/openFileInPreview";
5360
import { useAssetUrlRefresh, useAssetUrlState } from "~/assets/assetUrls";
@@ -61,7 +68,8 @@ import { useTheme } from "~/hooks/useTheme";
6168
import { getLocalStorageItem, setLocalStorageItem, useLocalStorage } from "~/hooks/useLocalStorage";
6269
import { resolveDiffThemeName } from "~/lib/diffRendering";
6370
import { PREFERRED_HIGHLIGHTER } from "~/lib/syntaxHighlighting";
64-
import { cn } from "~/lib/utils";
71+
import { isEditableFocused } from "~/lib/editableFocus";
72+
import { cn, isMacPlatform } from "~/lib/utils";
6573
import type { ChatFileAttachment } from "~/types";
6674
import { isHostPath } from "@t3tools/shared/path";
6775
import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
@@ -915,6 +923,18 @@ function EditableFileSurface({
915923
);
916924
}
917925

926+
function selectRenderedContentOnSelectAll(event: ReactKeyboardEvent<HTMLElement>) {
927+
const mac = isMacPlatform(navigator.platform);
928+
const selectAll =
929+
event.key.toLowerCase() === "a" &&
930+
(mac ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey) &&
931+
!event.shiftKey &&
932+
!event.altKey;
933+
if (!selectAll || isEditableFocused(event.target)) return;
934+
event.preventDefault();
935+
window.getSelection()?.selectAllChildren(event.currentTarget);
936+
}
937+
918938
function RenderedMarkdownSurface({
919939
environmentId,
920940
cwd,
@@ -941,7 +961,7 @@ function RenderedMarkdownSurface({
941961
useFileSaveSession(saveTarget, onPendingChange);
942962

943963
return (
944-
<ScrollArea className="min-h-0 flex-1">
964+
<ScrollArea className="min-h-0 flex-1" onKeyDown={selectRenderedContentOnSelectAll}>
945965
<FileMarkdownPreview
946966
text={contents}
947967
cwd={cwd}

0 commit comments

Comments
 (0)