Files
codex/codex-rs/tui/src/markdown_render/task_lists.rs
T
Felipe Coury a33fb9751c 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
2026-09-24 17:55:29 +00:00

40 lines
1.6 KiB
Rust

//! Task-list checkboxes replace unordered bullets and retain ordered numbering.
//! Keep the hanging indent aligned with the task text, including in loose lists.
use super::Writer;
use ratatui::text::Span;
impl Writer<'_, '_> {
pub(super) fn task_list_marker(&mut self, checked: bool) {
let Some(context) = self
.indent_stack
.iter_mut()
.rev()
.find(|context| context.is_list)
else {
return;
};
if let Some(marker) = context.marker.as_mut()
&& let Some(span) = marker.last_mut()
{
let prefix = span.content.strip_suffix("• ").unwrap_or(&span.content);
let checkbox = if checked { "☑" } else { "☐" };
span.content = format!("{prefix}{checkbox} ").into();
context.prefix = vec![Span::from(" ".repeat(Self::spans_display_width(marker)))];
context
.copy_marker
.push_str(if checked { "[x] " } else { "[ ] " });
}
if self.current_line_content.is_some() {
// Loose lists start their paragraph before the task marker arrives.
self.current_initial_indent = self.prefix_spans(/*pending_marker_line*/ true);
self.current_subsequent_indent = self.prefix_spans(/*pending_marker_line*/ false);
self.copy_line.prefix = self.copy_prefix(/*pending_marker_line*/ true);
self.copy_line.continuation = self.copy_prefix(/*pending_marker_line*/ false);
self.copy_line
.item_prefix
.clone_from(&self.copy_line.prefix);
}
}
}