Skip to content

fix(web): copy final code block lines as plain text - #8044

Open
jinrehacek wants to merge 2 commits into
pingdotgg:mainfrom
jinrehacek:fix/code-block-final-line-copy
Open

fix(web): copy final code block lines as plain text#8044
jinrehacek wants to merge 2 commits into
pingdotgg:mainfrom
jinrehacek:fix/code-block-final-line-copy

Conversation

@jinrehacek

@jinrehacek jinrehacek commented Aug 24, 2026

Copy link
Copy Markdown

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)
  • targeted formatter and lint checks for the two changed files
  • vp run --filter @t3tools/web typecheck
  • manually verified in the web client with final-line and single-line triple-click selections

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

chatMarkdownClipboardPayload now uses plainTextForCodeSelection. If the selection is inside pre, or starts there and the trailing fragment has no serialized text (whitespace/newline only), it copies range.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 returns range.toString() when a selection is fully within a <pre> or only its trailing boundary exits the block with no following content. Otherwise it returns null so the caller falls back to markdown serialization. Updates chatMarkdownClipboardPayload to use this helper instead of the prior inline closest('pre') check.

  • Risk: selections starting in a code block and continuing into prose now correctly serialize as markdown rather than plain text; reviewers should confirm no existing copy flows relied on the old broad plain-text behavior.

Macroscope summarized 88516f9.

Copilot AI lite review requested due to automatic review settings August 24, 2026 00:29
@coderabbitai

coderabbitai Bot commented Aug 24, 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: c1ed3432-aa18-47d5-b3f9-16ff9986da82

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 vouch:unvouched PR author is not yet trusted in the VOUCHED list. label Aug 24, 2026
@github-actions github-actions Bot added the size:M 30-99 changed lines (additions + deletions). label Aug 24, 2026

Copilot AI 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.

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.

@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 ccd2921. Configure here.

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

macroscopeapp Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 88516f9

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 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.

[Bug]: Triple-clicking the last line of a code block copies Markdown fences

2 participants