Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): copy code block selections without markdown #9175

Closedflamboh(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/9175/headopened View on GitHub

Note

🤖 GPT-5.6 Sol on behalf of Oliver

Problem

Selecting text inside a fenced code block can produce a browser range whose endpoint sits on the block wrapper. T3 treated that as a mixed Markdown selection, so copying a command could include the language tag, code fences, and extra blank lines instead of just the selected code.

For example,

copying

`bash cd ~/.t3/worktrees`

would copy the surrounding nmarkdown, not just "cd ~/.t3/worktrees"

Fix

Check the first and last selected text nodes. When both belong to the same <pre> element, copy the browser selection as plain text. Selections that cross prose or multiple code blocks still use the existing Markdown serializer.

UI changes

Before

https://github.com/user-attachments/assets/338cf6db-6933-4910-a1d0-af8d5f757ab4

After

https://github.com/user-attachments/assets/f33cb711-9d50-405c-8796-68fc70b6d010

Verification

  • vp lint apps/web/src/markdown-clipboard.ts --report-unused-disable-directives
  • vp fmt --check apps/web/src/markdown-clipboard.ts
  • vp run --filter @t3tools/web typecheck
  • git diff --check origin/main...HEAD

Changes prepared by GPT-5.6 Sol through Codex in T3 Code.

Note

Fix copying code block selections to include plain text only

  • Adds isSelectionInsideSingleCodeBlock in markdown-clipboard.ts to detect selections containing exactly one preformatted block with no serialized markdown outside it.
  • Updates chatMarkdownClipboardPayload to use this classifier, so single-code-block selections are copied as direct range text and sanitized HTML instead of rendered markdown.
  • Previously, selections whose common ancestor was outside the code block were treated as markdown and serialized incorrectly.
Macroscope summarized 2508f3c.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at 2508f3c

      Macroscope's review found this PR approvable — This is a focused one-file clipboard bug fix that changes only how selections wholly belonging to a single rendered code block are copied, preserving the existing Markdown path for other selections. It introduces no defaults, static-analysis overrides, schema changes, or sensitive-area modifications.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. flamboh(GitHub profile, opens in a new tab) changed the title

Sign in to join this conversation.