Add a response target picker to /copy (#39997)

## What changed

- Open a picker for `/copy` with the whole response plus each fenced code block and blockquote from the latest response.
- Label code blocks by language, show content previews, and preserve source whitespace and nested quote Markdown when copying an individual target.
- Keep the picker from disturbing terminal scrollback or queued input, retain clipboard leases, and avoid writing copied content to the session log.

## Testing

- Add coverage for target extraction, picker navigation and cancellation, exact copied content, plan responses, queued input, scrollback preservation, clipboard failures, and session logging.

GitOrigin-RevId: 77a35bc99f4f45932d39914f9a709b30fe8cd7c2
This commit is contained in:
Benjamin Carlsson authored and copyberry committed 2026-08-21 19:23:26 +00:00
1 parent 950dd184a1
commit df6a54ee85
15 files changed
+766 -30

No files matched your search

+71
View File
@@ -5825,6 +5825,77 @@ async fn resize_reflow_wraps_transcript_early_when_pet_is_enabled() {
);
}
#[tokio::test]
async fn copy_picker_opening_preserves_terminal_scrollback_without_reflow() {
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
let response = "Existing response\n\n```rust\nkeep_scrollback();\n```";
app.chat_widget.handle_server_notification(
ServerNotification::ItemCompleted(codex_app_server_protocol::ItemCompletedNotification {
thread_id: String::new(),
turn_id: "turn-1".to_string(),
completed_at_ms: 0,
item: serde_json::from_value(serde_json::json!({
"type": "agentMessage",
"id": "message-1",
"text": response,
}))
.expect("valid completed agent message"),
}),
/*replay_kind*/ None,
);
while app_event_rx.try_recv().is_ok() {}
app.transcript_cells = vec![
plain_line_cell("Older terminal scrollback"),
Arc::new(AgentMarkdownCell::new(
response.to_string(),
Path::new("/tmp"),
)),
];
app.deferred_history_lines = vec![Line::from("Buffered scrollback").into()];
app.has_emitted_history_lines = true;
app.scrollback_has_older_history = true;
app.transcript_reflow.note_width(/*width*/ 80);
let before = app
.render_transcript_lines_for_reflow(/*width*/ 80)
.lines
.iter()
.map(rendered_line_text)
.collect::<Vec<_>>();
app.chat_widget.apply_external_edit("/copy".to_string());
assert!(!render_bottom_popup(&app.chat_widget, /*width*/ 80).contains("Whole response"));
app.chat_widget
.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
assert!(render_bottom_popup(&app.chat_widget, /*width*/ 80).contains("Whole response"));
assert_eq!(
app.render_transcript_lines_for_reflow(/*width*/ 80)
.lines
.iter()
.map(rendered_line_text)
.collect::<Vec<_>>(),
before
);
assert_eq!(app.transcript_cells.len(), 2);
assert_eq!(app.deferred_history_lines.len(), 1);
assert!(app.has_emitted_history_lines);
assert!(app.scrollback_has_older_history);
assert!(!app.transcript_reflow.has_pending_reflow());
while let Ok(event) = app_event_rx.try_recv() {
assert!(
!matches!(
event,
AppEvent::ClearUi { .. }
| AppEvent::ClearUiAndSubmitUserMessage { .. }
| AppEvent::InsertHistoryCell(_)
| AppEvent::ConsolidateAgentMessage { .. }
),
"opening a picker must not modify terminal scrollback: {event:?}"
);
}
}
#[tokio::test]
async fn uncapped_resize_reflow_renders_all_cells_under_row_limit() {
let (mut app, _rx, _op_rx) = make_test_app_with_channels().await;