Skip to content

fix(web): keep selected code blocks plain - #7973

Open
spaansba wants to merge 1 commit into
pingdotgg:mainfrom
spaansba:fix/code-block-double-click-copy
Open

fix(web): keep selected code blocks plain#7973
spaansba wants to merge 1 commit into
pingdotgg:mainfrom
spaansba:fix/code-block-double-click-copy

Conversation

@spaansba

@spaansba spaansba commented Aug 23, 2026

Copy link
Copy Markdown

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.ts
  • vp lint apps/web/src/markdown-clipboard.ts apps/web/src/markdown-clipboard.test.ts
  • vp run typecheck in apps/web

No 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.

serializeRenderedMarkdownFragment now takes an Element, strips empty pre nodes, 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 serializeRenderedMarkdownFragment to keep single code blocks plain

  • Changes the parameter type of serializeRenderedMarkdownFragment from Node to Element and removes empty <pre> elements before serializing.
  • When the selection is exactly one non-empty code block, returns the block's raw text content with trailing newline stripped; otherwise returns fenced/normal markdown as before.
  • Updates test helpers in markdown-clipboard.test.ts: FakeElement gains parentElement, remove, hasChildNodes, and querySelectorAll; the cast helper is renamed to asElement and returns Element.
  • Risk: callers of serializeRenderedMarkdownFragment must now pass an Element instead of a Node; in-tree call sites are updated but out-of-tree callers will break.

Macroscope summarized f00a2c2.

@github-actions github-actions Bot added the vouch:unvouched PR author is not yet trusted in the VOUCHED list. label Aug 23, 2026
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 40e95c94-c221-43f5-b789-0e94610ee460

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the size:M 30-99 changed lines (additions + deletions). label Aug 23, 2026
Comment thread apps/web/src/markdown-clipboard.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread apps/web/src/markdown-clipboard.ts Outdated
@macroscopeapp

macroscopeapp Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: 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.

@spaansba
spaansba force-pushed the fix/code-block-double-click-copy branch from 0b93e90 to 5286d86 Compare August 23, 2026 07:46
@github-actions github-actions Bot added size:S 10-29 changed lines (additions + deletions). and removed size:M 30-99 changed lines (additions + deletions). labels Aug 23, 2026
Comment thread apps/web/src/markdown-clipboard.ts Outdated
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.
@spaansba
spaansba force-pushed the fix/code-block-double-click-copy branch from 5286d86 to f00a2c2 Compare August 23, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant