Repository navigation
Copy message selections without inherited block Markdown - #5776
Merged
Merged
Conversation
selectionClipboard rebuilt every ancestor of the selection up to the message root, so copying a word from a heading, list item, quote or table cell produced "## word", "- word", "> word" or a one-cell table, and a URL alone in a list item copied as "2. [url](url)". A selection inside one block now copies its inline content only. Block structure is kept when the selection spans blocks: the common container's markers, plus the list or table its selected items and cells need. The range is first trimmed to its selected content, so triple-clicks that end at the start of the next block no longer copy an empty item. Links whose visible text is their own URL (bare, www and email autolinks) copy as the selected text, unescaped, so they paste into a browser address bar. Named links keep their Markdown. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Oct 28, 2026
#6487) 🚨 **SLOP COP** 🚨 · `new-issue-autopilot` ## Human comments ## What was wrong Selection copy writes Markdown to `text/plain`, so Markdown syntax leaked into pastes where people expect the visible text (the same class as #6376 and #5776): - **Inline code (#6484):** copying a code-only selection such as `valet restart nginx` pasted `` `valet restart nginx` ``. Only `pre` bypassed the serializer. - **Formatted spans:** copying a word inside bold, italic, strikethrough or a link pasted `**important**` or `[deployment](https://example.com/deploy)`. - **Prose escapes:** `escapeText` escaped every `` \ ` * _ [ ] < > ``, so copying `config_loader.py`, `C:\Users\me\notes.txt` or `x < y, arr[0]` pasted `config\_loader.py`, `C:\\Users\\me\\notes.txt` and `x \< y, arr\[0\]`. It also turned `<https://example.com>` into `<https://example.com\>`, which re-renders as the wrong URL. ## What changed - `selectionClipboard` copies the visible text when the whole selection sits inside one `pre`, inline `code`, link, `strong`/`b`, `em`/`i` or `del`/`s` span. Wider selections, cross-message selections and Add to chat keep Markdown. Math inside such a span still copies as TeX, because KaTeX's hidden duplicate layout would otherwise be pasted twice. - `escapeText` escapes a character only where Markdown would reinterpret it: `_` unless between letters or digits, `\` before punctuation or at the end, `[` and `>` at line start, `]` before `(`, `[` or `:`, `<` before a tag or autolink start, and always `` ` `` and `*`. - Rich HTML is unchanged. No public API, wire, schema or storage changes. ## How you verified - Real app (`pnpm start:worktree`, headless Chromium, real mouse triple-click, double-click and drag on an agent reply, reading the copy event's `text/plain`), main compared with this branch: | Selection | main | this PR | | --- | --- | --- | | triple-click / drag `valet restart nginx` | `` `valet restart nginx` `` | `valet restart nginx` | | double-click `my_old_var` in prose | `my\_old\_var` | `my_old_var` | | `Open C:\Users\me\notes.txt` paragraph | `C:\\Users\\me\\notes.txt` | `C:\Users\me\notes.txt` | | `x < y and y > z, arr[0]` paragraph | `x \< y and y \> z, arr\[0\]` | unchanged text | | double-click a bold word | `**important**` | `important` | | word inside a named link | `[deployment](https://example.com/deploy)` | `deployment` | | paragraph mixing prose, bold and italic, lists, quotes, tables, whole message | Markdown | unchanged Markdown | - New tests: visible-text copy for every span type across five selection shapes; a round trip that copies tricky prose, re-renders the copied Markdown and requires the same text (fails on main for the over-escaped cases and the autolink); math inside bold (fails without the math guard). Four existing tests that pinned the old Markdown-around-a-span output were updated. - `pnpm exec turbo run test --filter=@bb/app -- src/components/thread/timeline src/components/secondary-panel src/lib src/components/ui/markdown-preview`: 215 files, 2173 passed. `pnpm exec turbo run lint typecheck --filter=@bb/app` passes. - Not verified: native Cmd+C in bb Desktop or Android (same DOM copy path). Fixes #6484 > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- slopcop:rule=new-issue-autopilot run=run_6fij7oq0mvsmw015 sha=issue-6484 kind=summary --> --------- Co-authored-by: SawyerHood <[email protected]> Co-authored-by: Michael Yong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
selectionClipboard(apps/app/src/lib/markdown-clipboard.ts) cloned the selected range and then rebuilt every ancestor up to the message root before serializing. Any partial selection therefore inherited the Markdown of its enclosing blocks: selecting a word in a heading, list item, quote or table cell copied## word,- word,> wordor| word |\n| --- |, in bothtext/plainandtext/html. Links were always serialized as[text](href)with Markdown escaping, so copying a bare URL produced[https://example.com/a\_b](https://example.com/a_b), which is useless when pasted into a browser address bar. A URL alone in a list item copied as2. [url](url).What changed
markdown-clipboard.ts:pre) around a selection are still kept.## Heading\n\n3.).[x]/[ ]marker.www.and email autolinks) copy as the selected text, unescaped. Named links keep[text](href).readSelectedMessageMarkdown) and secondary-panel selections.ThreadTimelineRows.actions.test.tsx: the partial-link Add to chat case now expects[oc](https://example.com)instead of- [oc](https://example.com).Four, not4. Four. The ordered-number test now covers a two-item selection (4. Four\n5. Five).How you verified
SelectableMessageProse.clipboard.test.tsx:www., email and list-item URLs, plus a named link.mainand pass with this change.pnpm exec turbo run typecheck lint test --filter=@bb/apppasses (6062 tests).pnpm start:worktreebuild, using real mouse drags and triple-clicks on an agent reply, then reading the copy event's clipboard data:https://github.com/get-bb/bb/pull/1234?tab=files_changed#diff_a_b[the docs](https://docs.example.com/guide)Hello **bold** wordsFourNested item3. Three\n4. Four> Quoted *emphasis* words\n> \n> Second| some cell text | other |\n| --- | --- |🤖 Generated with Claude Code