mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
Suppress repeated image paste presses in legacy terminals (#51411)
## Why Legacy terminals report key auto-repeat as new presses, which can trigger repeated image pastes when presses accumulate during a slow paste. ## What changed Suppress repeated `Ctrl+V` and `Alt+V` image paste presses within a sliding 250 ms window, refreshed after each suppressed press and after a paste completes. Clear suppression on other ordinary key presses or key release events so a fresh paste can proceed immediately. ## Testing Add regression coverage for repeated presses, window expiry, and resetting suppression on another key press or a key release. Update the shortcut remapping test to release the key between image pastes. GitOrigin-RevId: 45abc056e5bda47d1c9704702e369e63dcce29db
This commit is contained in:
@@ -2511,10 +2511,15 @@ async fn slash_keymap_invalid_args_show_usage() {
|
||||
async fn copy_shortcut_can_be_remapped() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
for modifiers in [KeyModifiers::CONTROL, KeyModifiers::ALT] {
|
||||
let paste = KeyEvent::new(KeyCode::Char('v'), modifiers);
|
||||
assert_matches!(
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Char('v'), modifiers)),
|
||||
chat.handle_key_event(paste),
|
||||
crate::chatwidget::KeyEventAction::PasteImage
|
||||
);
|
||||
chat.handle_key_event(KeyEvent {
|
||||
kind: KeyEventKind::Release,
|
||||
..paste
|
||||
});
|
||||
}
|
||||
let mut keymap_config = chat.config_ref().tui_keymap.clone();
|
||||
keymap_config.global.copy = Some(codex_config::types::KeybindingsSpec::One(
|
||||
@@ -2543,6 +2548,29 @@ async fn copy_shortcut_can_be_remapped() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn legacy_image_paste_ignores_buffered_press_until_other_input() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let paste = KeyEvent::new(KeyCode::Char('v'), KeyModifiers::CONTROL);
|
||||
|
||||
assert_matches!(chat.handle_key_event(paste), KeyEventAction::PasteImage);
|
||||
assert_matches!(chat.handle_key_event(paste), KeyEventAction::None);
|
||||
|
||||
chat.suppress_image_paste_until = Instant::now() - Duration::from_secs(/*secs*/ 1);
|
||||
assert_matches!(chat.handle_key_event(paste), KeyEventAction::PasteImage);
|
||||
|
||||
chat.suppress_image_paste_until = Instant::now() + Duration::from_secs(/*secs*/ 1);
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Char('x')));
|
||||
assert_matches!(chat.handle_key_event(paste), KeyEventAction::PasteImage);
|
||||
|
||||
chat.suppress_image_paste_until = Instant::now() + Duration::from_secs(/*secs*/ 1);
|
||||
chat.handle_key_event(KeyEvent {
|
||||
kind: KeyEventKind::Release,
|
||||
..paste
|
||||
});
|
||||
assert_matches!(chat.handle_key_event(paste), KeyEventAction::PasteImage);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn copy_shortcut_submits_markdown_and_reports_completion_once() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
|
||||
Reference in New Issue
Block a user