Preserve Markdown formatting when copying transcript selections (#47896)

## Why

Transcript selections were copied as plain text, losing the formatting of rendered Markdown when pasted.

## What changed

- Retain semantic Markdown annotations through rendering, wrapping, and streaming, then serialize selected text with balanced markup.
- Preserve inline formatting, web links, headings, lists, blockquotes, and hard breaks in Markdown clipboard payloads.
- Keep code-only and other literal-only selections as plain text. In mixed selections, escape user prose and fence code, tables, and tool output to preserve their literal content.

## Testing

Add unit tests and Markdown/HTML snapshots covering partial selections, nested containers, escaping, links, resize stability, and streaming boundaries.

GitOrigin-RevId: f0476334a6bf8ad0fb57626627bd258443540852
This commit is contained in:
Felipe Coury
2026-09-24 17:55:29 +00:00
committed by copyberry
parent f6fd7f17ed
commit a33fb9751c
38 changed files with 1790 additions and 41 deletions
@@ -98,7 +98,7 @@ fn copy_shortcuts_clear_selection_only_after_confirmed_delivery() {
&cells,
&text,
/*clear_selection*/ true,
|text| {
|text, _format| {
assert_eq!(text, "selected\tcafé");
Err("clipboard unavailable".to_string())
},
@@ -118,7 +118,7 @@ fn copy_shortcuts_clear_selection_only_after_confirmed_delivery() {
&cells,
&text,
/*clear_selection*/ true,
|text| {
|text, _format| {
assert_eq!(text, "selected\tcafé");
Ok(status)
},
@@ -169,7 +169,7 @@ fn command_c_ignores_release_and_copies_only_an_active_selection() {
panic!("Cmd+C must copy the transcript selection");
};
assert_eq!(text, "selected café");
view.copy_selected_text_with(&cells, &text, /*clear_selection*/ true, |_| {
view.copy_selected_text_with(&cells, &text, /*clear_selection*/ true, |_, _format| {
Ok(crate::clipboard_copy::CopyStatus::Confirmed)
})
.unwrap();
@@ -648,7 +648,7 @@ fn pending_copy_only_finishes_the_original_selection() {
&cells,
&selected,
/*clear_selection*/ true,
|_| Ok(CopyStatus::Pending(1)),
|_, _format| Ok(CopyStatus::Pending(1)),
)
.unwrap();
view.follow_pending_copy();