fix(web): keep selected code blocks plain - #7973
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0b93e90. Configure here.
ApprovabilityVerdict: Skipped Macroscope did not run approvability analysis for this PR. Macroscope could not determine whether this PR modifies its approvability configuration, so the PR was not approved automatically. A PR that may change the rules that govern approval is never approved automatically. |
0b93e90 to
5286d86
Compare
Treat a selection containing only one non-empty code block as plain text, even when the browser clones pre wrappers around it. Preserve fenced Markdown when prose is selected with the block.
5286d86 to
f00a2c2
Compare

Selecting a command by double-clicking can clone
<pre>wrappers around the browser range. The Markdown clipboard serializer then copies fences, sometimes including an extra empty fenced block, instead of the selected command.This change removes childless boundary wrappers from the cloned fragment, serializes the complete selection, and returns plain text only when that serialization contains exactly one code block and nothing else. Genuine rendered empty code blocks retain their
<code>child and their Markdown fences. Selections containing prose or non-text Markdown content still preserve their full Markdown representation.Testing:
vp test run apps/web/src/markdown-clipboard.test.tsvp lint apps/web/src/markdown-clipboard.ts apps/web/src/markdown-clipboard.test.tsvp run typecheckinapps/webNo visual UI change. Seven focused tests cover the exact fenced clipboard output, genuine empty blocks, and preservation of mixed content.
Implemented with GPT-5.6 Sol via the Codex harness in T3 Code.
Note
Low Risk
Clipboard serialization only; no auth, data, or security-sensitive paths. Worst case is incorrect copy formatting.
Overview
Copying a selected command no longer pastes extra markdown fences when the browser clones empty
<pre>wrappers around the range.serializeRenderedMarkdownFragmentnow takes anElement, strips emptyprenodes, then returns raw code text only if the selection serializes to exactly one non-empty code block. Mixed selections (prose, rules, etc.) still keep full markdown, including empty fenced blocks that were actually rendered.Reviewed by Cursor Bugbot for commit f00a2c2. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix
serializeRenderedMarkdownFragmentto keep single code blocks plainserializeRenderedMarkdownFragmentfromNodetoElementand removes empty<pre>elements before serializing.FakeElementgainsparentElement,remove,hasChildNodes, andquerySelectorAll; the cast helper is renamed toasElementand returnsElement.serializeRenderedMarkdownFragmentmust now pass anElementinstead of aNode; in-tree call sites are updated but out-of-tree callers will break.Macroscope summarized f00a2c2.