feat: add text cleared with ctrl+c to the history so it can be recovered with up arrow (#5470)

https://github.com/user-attachments/assets/5eed882e-6a54-4f2c-8f21-14fa0d0ef347
This commit is contained in:
Javi
2025-10-21 16:45:16 -07:00
committed by GitHub
parent cdd106b930
commit db7eb9a7ce
2 changed files with 65 additions and 5 deletions

View File

@@ -692,6 +692,40 @@ fn ctrl_c_shutdown_ignores_caps_lock() {
}
}
#[test]
fn ctrl_c_cleared_prompt_is_recoverable_via_history() {
let (mut chat, _rx, mut op_rx) = make_chatwidget_manual();
chat.bottom_pane.insert_str("draft message ");
chat.bottom_pane
.attach_image(PathBuf::from("/tmp/preview.png"), 24, 42, "png");
let placeholder = "[preview.png 24x42]";
assert!(
chat.bottom_pane.composer_text().ends_with(placeholder),
"expected placeholder {placeholder:?} in composer text"
);
chat.handle_key_event(KeyEvent::new(KeyCode::Char('c'), KeyModifiers::CONTROL));
assert!(chat.bottom_pane.composer_text().is_empty());
assert_matches!(op_rx.try_recv(), Err(TryRecvError::Empty));
assert!(chat.bottom_pane.ctrl_c_quit_hint_visible());
chat.handle_key_event(KeyEvent::new(KeyCode::Up, KeyModifiers::NONE));
let restored_text = chat.bottom_pane.composer_text();
assert!(
restored_text.ends_with(placeholder),
"expected placeholder {placeholder:?} after history recall"
);
assert!(restored_text.starts_with("draft message "));
assert!(!chat.bottom_pane.ctrl_c_quit_hint_visible());
let images = chat.bottom_pane.take_recent_submission_images();
assert!(
images.is_empty(),
"attachments are not preserved in history recall"
);
}
#[test]
fn exec_history_cell_shows_working_then_completed() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual();