fix(web): copy final code block lines as plain text - #8044
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.
Pull request overview
Fixes web clipboard handling so final or single-line code selections copy as plain code instead of fenced Markdown.
Changes:
- Detects code selections trailing only whitespace outside
<pre>. - Preserves Markdown serialization when selections extend into prose.
- Adds focused unit tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
apps/web/src/markdown-clipboard.ts |
Implements plain-text handling for eligible code selections. |
apps/web/src/markdown-clipboard.test.ts |
Tests contained, final-line, and prose-spanning selections. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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 ccd2921. Configure here.
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This is a focused clipboard bug fix that changes only how code-block selections are classified, preserving Markdown serialization for selections that extend into prose. The added unit tests cover the new final-line behavior and the surrounding fallback cases. You can add or adjust custom eligibility rules. Learn more. |

Fixes #8042.
Triple-clicking the final or only line of a code block can place the selection's trailing boundary outside
<pre>. The clipboard handler then serializes the partial block back into fenced Markdown.Treat the selection as plain code when it starts inside
<pre>and contains no non-whitespace text after the block. Selections that continue into prose still use the Markdown serializer.Tests:
vp test run --project unit src/markdown-clipboard.test.ts(6 passed)vp run --filter @t3tools/web typecheckBuilt with GPT-5.6-Sol using the Codex harness.
Note
Low Risk
Clipboard-only copy-path tweak for chat markdown; no auth, data, or security changes. Mixed code-plus-prose selections still go through the existing Markdown serializer.
Overview
Fixes copying the last (or only) line of a code block: triple-click can put the range’s trailing boundary outside
<pre>, which previously serialized the snippet as fenced Markdown.chatMarkdownClipboardPayloadnow usesplainTextForCodeSelection. If the selection is insidepre, or starts there and the trailing fragment has no serialized text (whitespace/newline only), it copiesrange.toString(). Selections that continue into prose still use Markdown serialization.Reviewed by Cursor Bugbot for commit 88516f9. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix copying final code block lines as plain text in web client
Adds
plainTextForCodeSelection(range)to markdown-clipboard.ts, which returnsrange.toString()when a selection is fully within a<pre>or only its trailing boundary exits the block with no following content. Otherwise it returnsnullso the caller falls back to markdown serialization. UpdateschatMarkdownClipboardPayloadto use this helper instead of the prior inlineclosest('pre')check.Macroscope summarized 88516f9.