Skip to content

Keep block code plain when copying from rendered markdown - #4468

Merged
juliusmarminge merged 1 commit into
pingdotgg:mainfrom
yashranaway:copy-plain-code-selection
Aug 15, 2026
Merged

Keep block code plain when copying from rendered markdown#4468
juliusmarminge merged 1 commit into
pingdotgg:mainfrom
yashranaway:copy-plain-code-selection

Conversation

@yashranaway

@yashranaway yashranaway commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

What Changed

The markdown clipboard serializer now recognizes block code that arrives without its pre wrapper (highlighter line spans or embedded newlines) and copies it verbatim instead of wrapping it like inline code. Real inline code keeps its backticks.

Why

Selecting the contents of a rendered code block can produce a copy fragment holding the code element but not its pre parent, most visibly on Firefox. The serializer fell into the inline-code branch and wrapped the copied text in single backticks. Pasting that into a shell runs the command inside command substitution:

λ `git show-ref --verify refs/remotes/origin/opt/deploy/dev`
zsh: 97649d91...: command not found

Copies that legitimately span prose plus a whole code block still include the pre element and keep their fenced form, so the markdown-preserving copy feature is unchanged.

Fixes #4368

Testing

  • vp test run apps/web/src/markdown-clipboard.test.ts passes (3/3): inline code still wrapped, highlighted block selection stays plain, multi-line selection stays plain
  • pnpm typecheck in apps/web clean
  • vp lint on changed files clean

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Low Risk
Small, localized change to markdown copy serialization with new unit tests; no auth, data, or API impact.

Overview
Copying from rendered chat markdown no longer wraps block code in single backticks when the selection only includes the inner code node (common in Firefox) instead of the surrounding pre.

serializeRenderedMarkdownFragment now uses isBlockCodeElement to treat CODE as block when the text has newlines or Shiki-style .line child spans, and returns plain text in those cases. True inline code still gets backtick wrapping.

Unit tests cover inline code, highlighted block fragments without pre, and multi-line selections.

Reviewed by Cursor Bugbot for commit 3f7588a. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Keep block code plain when copying from rendered markdown

When copying from rendered markdown, CODE elements that represent block code were incorrectly wrapped in backticks. The fix introduces isBlockCodeElement in markdown-clipboard.ts, which checks for newlines in content or child elements with class line (used by syntax-highlighted blocks). Block code is now returned as plain text; only inline code gets backtick wrapping.

Macroscope summarized 3f7588a.

@coderabbitai

coderabbitai Bot commented Jul 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: 496d76c0-caf7-49cd-8156-7bb38de08afa

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Jul 24, 2026
@macroscopeapp

macroscopeapp Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

Small bug fix that prevents block code from being incorrectly wrapped in backticks when copying from rendered markdown. The change is self-contained with comprehensive unit tests covering the new behavior.

You can customize Macroscope's approvability policy. Learn more.

@juliusmarminge
juliusmarminge enabled auto-merge (squash) August 15, 2026 10:43
Selecting the contents of a code block could produce a fragment holding
the code element without its pre wrapper, most visibly on Firefox. The
markdown clipboard serializer then treated it as inline code and wrapped
the copied shell command in backticks, which executes command
substitution if pasted into a shell unedited.

Recognize block code by its highlighter line spans or embedded newlines
and copy it verbatim. Real inline code keeps its backticks.

Fixes pingdotgg#4368
@juliusmarminge
juliusmarminge force-pushed the copy-plain-code-selection branch from 4847b45 to 3f7588a Compare August 15, 2026 12:08
@juliusmarminge
juliusmarminge merged commit 7083bce into pingdotgg:main Aug 15, 2026
15 checks passed
@yashranaway
yashranaway deleted the copy-plain-code-selection branch August 15, 2026 12:15
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Aug 15, 2026
## What's Changed
* fix(desktop): route mouse thumb buttons to the in-app browser by @akosbalogh in pingdotgg/t3code#4459
* fix(web): keep the final segment of directory paths with a trailing separator by @jorvarea in pingdotgg/t3code#5460
* Keep block code plain when copying from rendered markdown by @yashranaway in pingdotgg/t3code#4468
* fix(web): add web app manifest so installed app keeps its scope by @Albro3459 in pingdotgg/t3code#4306
* Skip user hooks during Claude capability probes by @yashranaway in pingdotgg/t3code#4466
* fix(mobile): use Android monospace font family by @tastelessjolt in pingdotgg/t3code#4609
* fix(desktop): timestamps follow the OS locale instead of en-US by @brzzdev in pingdotgg/t3code#6190
* fix(web): keep multi-select questions open after the first click by @RaitP1 in pingdotgg/t3code#6646
* fix(web): stop clipping the changed-files expand hover on Windows by @mrmg in pingdotgg/t3code#6545
* fix(server): allow long-running git pushes by @devchaudhary24k in pingdotgg/t3code#6499
* fix(desktop): keep probing backend readiness while the process is alive by @lgwacker in pingdotgg/t3code#5526
* fix(server): allow install scripts in npm-global provider updates by @hey-jj in pingdotgg/t3code#5646
* fix: detect SSH remotes with non-git user prefixes (e.g. gitlab@) by @JackatDJL in pingdotgg/t3code#3649
* fix(web): describe what Ultracode does in the Reasoning picker by @delltrak in pingdotgg/t3code#6092
* fix(server): settle pending user-input requests when a Claude session stops by @AaronAbuUsama in pingdotgg/t3code#5127
* fix(server): stop replaying a command receipt for a different aggregate by @ostapondo in pingdotgg/t3code#5246
* fix(server): settle snoozed threads immediately by @0bkevin in pingdotgg/t3code#5379
* fix(mobile): prevent crash on sign out in settings by @shubhu121 in pingdotgg/t3code#4899
* fix(mobile): local-checkout threads record their branch so PR badges show by @Zeus-Deus in pingdotgg/t3code#4986
* fix(web): contain long approval commands by @Serendeep in pingdotgg/t3code#6503
* feat(web): make right panel maximize bindable by @husseinraoouf in pingdotgg/t3code#5091
* fix(server): respect inherited OPENCODE_CONFIG_CONTENT by @jonocodes in pingdotgg/t3code#4242
* fix(marketing): detect Mac chip on homepage download button by @mahdibm-dev in pingdotgg/t3code#4197
* Keep the server alive when a response write hits a dead socket by @yashranaway in pingdotgg/t3code#4470
* Limit physical key fallback to non-Latin layout output by @yashranaway in pingdotgg/t3code#4469
* fix: restore CLAUDE.md symlink target by @NgoQuocViet2001 in pingdotgg/t3code#3929
* fix(clients): default clone destination to folder plus repo name by @inayayousfi in pingdotgg/t3code#5989
* fix(web): keep timestamp date and time in the same locale by @juliusmarminge in pingdotgg/t3code#7081
* feat(desktop): add signal macOS DMG installer background by @Brechard in pingdotgg/t3code#6201

## New Contributors
* @akosbalogh made their first contribution in pingdotgg/t3code#4459
* @jorvarea made their first contribution in pingdotgg/t3code#5460
* @yashranaway made their first contribution in pingdotgg/t3code#4468
* @Albro3459 made their first contribution in pingdotgg/t3code#4306
* @tastelessjolt made their first contribution in pingdotgg/t3code#4609
* @brzzdev made their first contribution in pingdotgg/t3code#6190
* @RaitP1 made their first contribution in pingdotgg/t3code#6646
* @devchaudhary24k made their first contribution in pingdotgg/t3code#6499
* @lgwacker made their first contribution in pingdotgg/t3code#5526
* @JackatDJL made their first contribution in pingdotgg/t3code#3649
* @delltrak made their first contribution in pingdotgg/t3code#6092
* @AaronAbuUsama made their first contribution in pingdotgg/t3code#5127
* @0bkevin made their first contribution in pingdotgg/t3code#5379
* @shubhu121 made their first contribution in pingdotgg/t3code#4899
* @Zeus-Deus made their first contribution in pingdotgg/t3code#4986
* @husseinraoouf made their first contribution in pingdotgg/t3code#5091
* @jonocodes made their first contribution in pingdotgg/t3code#4242
* @mahdibm-dev made their first contribution in pingdotgg/t3code#4197
* @NgoQuocViet2001 made their first contribution in pingdotgg/t3code#3929
* @inayayousfi made their first contribution in pingdotgg/t3code#5989

**Full Changelog**: pingdotgg/t3code@v0.0.34-nightly.20260815.1101...v0.0.34-nightly.20260815.1102

Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.0.34-nightly.20260815.1102
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.

[Bug]: copying surrounds text in backticks

2 participants