mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Preserve Markdown formatting when copying TUI responses (#42847)
## What changed - Add rendered HTML alongside the original Markdown when copying a whole response through the native clipboard, so rich-text destinations preserve headings, lists, tables, code, and other formatting. - Keep code-block, blockquote, transcript, terminal, and WSL clipboard copies as plain text. - Escape raw HTML, omit remote image sources, and render unsupported link destinations as visible text when producing clipboard HTML. ## Testing - Add coverage for rich formatting, local and unsafe links, inert images, fenced tables, copy selection formats, and clipboard fallbacks. GitOrigin-RevId: c6f5edd88b65f9e9b1ddc5618442868cf47ee560
This commit is contained in:
1 parent
9c4253ffc1
commit
7a8092a447
17 files changed
+329
-57
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
use super::*;
|
||||
use crate::bottom_pane::BottomPaneView;
|
||||
use crate::clipboard_copy::CopyFormat;
|
||||
|
||||
impl ChatWidget {
|
||||
pub(crate) fn set_agents_navigation_enabled(&mut self, enabled: bool) {
|
||||
@@ -283,9 +284,11 @@ impl ChatWidget {
|
||||
false
|
||||
}
|
||||
|
||||
/// Copy the last agent response (raw markdown) to the system clipboard.
|
||||
/// Copy the last response as Markdown with HTML for rich-text destinations.
|
||||
pub(crate) fn copy_last_agent_markdown(&mut self) {
|
||||
self.copy_last_agent_markdown_with(crate::clipboard_copy::copy_to_clipboard);
|
||||
self.copy_last_agent_markdown_with(|text| {
|
||||
crate::clipboard_copy::copy_to_clipboard(text, CopyFormat::Markdown)
|
||||
});
|
||||
}
|
||||
|
||||
/// Inner implementation with an injectable clipboard backend for testing.
|
||||
@@ -327,6 +330,7 @@ impl ChatWidget {
|
||||
let mut choices = vec![(
|
||||
"Whole response".to_string(),
|
||||
Arc::<str>::from(markdown.as_str()),
|
||||
CopyFormat::Markdown,
|
||||
)];
|
||||
let source = self
|
||||
.transcript
|
||||
@@ -343,21 +347,27 @@ impl ChatWidget {
|
||||
|language| format!("{language} code"),
|
||||
),
|
||||
content,
|
||||
CopyFormat::PlainText,
|
||||
)),
|
||||
crate::markdown::CopyTarget::Quote(content) => {
|
||||
let content: String = content
|
||||
.split_inclusive('\n')
|
||||
.map(|line| crate::git_action_directives::strip_line_directives(line).0)
|
||||
.collect();
|
||||
(!content.trim().is_empty())
|
||||
.then(|| ("Blockquote".to_string(), Arc::from(content)))
|
||||
(!content.trim().is_empty()).then(|| {
|
||||
(
|
||||
"Blockquote".to_string(),
|
||||
Arc::from(content),
|
||||
CopyFormat::PlainText,
|
||||
)
|
||||
})
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
let items = choices
|
||||
.into_iter()
|
||||
.map(|(label, text)| {
|
||||
.map(|(label, text, format)| {
|
||||
let description = text
|
||||
.lines()
|
||||
.find(|line| !line.trim().is_empty())
|
||||
@@ -369,6 +379,7 @@ impl ChatWidget {
|
||||
tx.send(AppEvent::CopySelection {
|
||||
text: Arc::clone(&text),
|
||||
label: label.clone(),
|
||||
format,
|
||||
});
|
||||
})],
|
||||
dismiss_on_select: true,
|
||||
@@ -386,8 +397,10 @@ impl ChatWidget {
|
||||
self.defer_input_until_settings_applied();
|
||||
}
|
||||
|
||||
pub(crate) fn copy_selection(&mut self, text: Arc<str>, label: String) {
|
||||
self.copy_selection_with(&text, &label, crate::clipboard_copy::copy_to_clipboard);
|
||||
pub(crate) fn copy_selection(&mut self, text: Arc<str>, label: String, format: CopyFormat) {
|
||||
self.copy_selection_with(&text, &label, |text| {
|
||||
crate::clipboard_copy::copy_to_clipboard(text, format)
|
||||
});
|
||||
}
|
||||
|
||||
pub(super) fn copy_selection_with(
|
||||
|
||||
Reference in new issue
Block a user