markdown: Support copying the Markdown source of a selection (#2628)
Closes #1244
## Description
`TextView` now has a `SelectionFormat`, so a selection can be copied as
its Markdown source instead of the rendered text.
`SelectionFormat::Plain` is the default and keeps the current behavior.
With `SelectionFormat::Source`, `TextViewState::selected_text` (what
copy writes to the clipboard) reconstructs the Markdown of the
selection: inline marks are re-wrapped (`**bold**`, `` `code` ``,
`[text](url)` …), headings keep their `#` prefix, list items keep their
marker, code blocks keep their fence, and top-level blocks are separated
by a blank line. Select-all returns the original source verbatim.
```rust
gpui_component::markdown(source)
.selectable(true)
.selection_format(SelectionFormat::Source)
```
## Screenshot
I don't have meaningful before and after, but in the screenshot below, I
intentionally selected within the heading and within some mark, used
`cmd-c` and pasted into MacDown:
<img width="1488" height="803" alt="image"
src="https://github.com/user-attachments/assets/800beb66-3d66-4fcf-b404-0d8f8994f18e"
/>
## How to Test
Just select text and copy as before, but it works only on views with
`SelectionFormat::Source`.
## Checklist
- [x] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document and
followed the guidelines.
- [x] Reviewed the changes in this PR and confirmed AI generated code
(If any) is accurate.
- [x] Passed `cargo run` for story tests related to the changes.
- [ ] Tested macOS, Windows and Linux platforms performance (if the
change is platform-specific)
---------
Co-authored-by: Jason Lee <huacnlee@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> S
Stephan Aßmus committed
8e20e3bb2055c71e66e176032c79063cee03bbab
Parent: 424f245
Committed by GitHub <noreply@github.com>
on 8/10/2026, 10:17:02 AM