Skip to content

Commit 4caec39

Browse files
fix(web): keep rendered Markdown select-all scoped after a task toggle
Clicking a task checkbox left focus on an input, which the editable guard treated as a text field and handed back to the document-wide select-all. The rendered preview has no text inputs, so drop that guard and only ignore keys that bubble in from portaled children such as the image dialog. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b24c06e commit 4caec39

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ describe("rendered Markdown task saves", () => {
164164
});
165165

166166
describe("rendered Markdown select all", () => {
167+
const selectAll = () =>
168+
userEvent.keyboard(
169+
isMacPlatform(navigator.platform) ? "{Meta>}a{/Meta}" : "{Control>}a{/Control}",
170+
);
171+
167172
it("selects only the rendered file content", async () => {
168173
using _settings = setup();
169174
await using screen = await render(
@@ -173,10 +178,22 @@ describe("rendered Markdown select all", () => {
173178
</>,
174179
);
175180
await userEvent.click(screen.getByText("Rendered file body."));
176-
const selectAll = isMacPlatform(navigator.platform)
177-
? "{Meta>}a{/Meta}"
178-
: "{Control>}a{/Control}";
179-
await userEvent.keyboard(selectAll);
181+
await selectAll();
182+
const selection = window.getSelection()?.toString() ?? "";
183+
expect(selection).toContain("Rendered file body.");
184+
expect(selection).not.toContain("Transcript text from the chat thread.");
185+
});
186+
187+
it("stays scoped to the file after toggling a task checkbox", async () => {
188+
using _settings = setup();
189+
await using screen = await render(
190+
<>
191+
<p>Transcript text from the chat thread.</p>
192+
{markdownPreview(false, "- [ ] Task item\n\nRendered file body.\n")}
193+
</>,
194+
);
195+
await userEvent.click(screen.getByRole("checkbox"));
196+
await selectAll();
180197
const selection = window.getSelection()?.toString() ?? "";
181198
expect(selection).toContain("Rendered file body.");
182199
expect(selection).not.toContain("Transcript text from the chat thread.");

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ import { useTheme } from "~/hooks/useTheme";
6868
import { getLocalStorageItem, setLocalStorageItem, useLocalStorage } from "~/hooks/useLocalStorage";
6969
import { resolveDiffThemeName } from "~/lib/diffRendering";
7070
import { PREFERRED_HIGHLIGHTER } from "~/lib/syntaxHighlighting";
71-
import { isEditableFocused } from "~/lib/editableFocus";
7271
import { cn, isMacPlatform } from "~/lib/utils";
7372
import type { ChatFileAttachment } from "~/types";
7473
import { isHostPath } from "@t3tools/shared/path";
@@ -930,7 +929,14 @@ function selectRenderedContentOnSelectAll(event: ReactKeyboardEvent<HTMLElement>
930929
(mac ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey) &&
931930
!event.shiftKey &&
932931
!event.altKey;
933-
if (!selectAll || isEditableFocused(event.target)) return;
932+
// React bubbles keys from portaled children (the image dialog) through this surface.
933+
if (
934+
!selectAll ||
935+
!(event.target instanceof Node) ||
936+
!event.currentTarget.contains(event.target)
937+
) {
938+
return;
939+
}
934940
event.preventDefault();
935941
window.getSelection()?.selectAllChildren(event.currentTarget);
936942
}

0 commit comments

Comments
 (0)