Skip to content

Commit 0046d89

Browse files
committed
fix(tui): don't arm quit when modal handles Ctrl+C
1 parent f479e1e commit 0046d89

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

codex-rs/tui/src/chatwidget.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3848,8 +3848,15 @@ impl ChatWidget {
38483848
/// quit.
38493849
fn on_ctrl_c(&mut self) {
38503850
let key = key_hint::ctrl(KeyCode::Char('c'));
3851+
let modal_or_popup_active = !self.bottom_pane.no_modal_or_popup_active();
38513852
if self.bottom_pane.on_ctrl_c() == CancellationEvent::Handled {
3852-
self.arm_quit_shortcut(key);
3853+
if modal_or_popup_active {
3854+
self.quit_shortcut_expires_at = None;
3855+
self.quit_shortcut_key = None;
3856+
self.bottom_pane.clear_quit_shortcut_hint();
3857+
} else {
3858+
self.arm_quit_shortcut(key);
3859+
}
38533860
return;
38543861
}
38553862

codex-rs/tui2/src/chatwidget.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3551,8 +3551,15 @@ impl ChatWidget {
35513551
/// quit.
35523552
fn on_ctrl_c(&mut self) {
35533553
let key = key_hint::ctrl(KeyCode::Char('c'));
3554+
let modal_or_popup_active = !self.bottom_pane.no_modal_or_popup_active();
35543555
if self.bottom_pane.on_ctrl_c() == CancellationEvent::Handled {
3555-
self.arm_quit_shortcut(key);
3556+
if modal_or_popup_active {
3557+
self.quit_shortcut_expires_at = None;
3558+
self.quit_shortcut_key = None;
3559+
self.bottom_pane.clear_quit_shortcut_hint();
3560+
} else {
3561+
self.arm_quit_shortcut(key);
3562+
}
35563563
return;
35573564
}
35583565

docs/exit-confirmation-prompt-design.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Priority order in the UI layer:
3535

3636
1. Active modal/view gets the first chance to consume (`BottomPane::on_ctrl_c`).
3737
- If the modal handles it, the quit flow stops.
38+
- When a modal/popup handles Ctrl+C, the quit shortcut is cleared so dismissing a modal cannot
39+
accidentally prime a subsequent Ctrl+C to quit.
3840
2. If the user has already armed Ctrl+C and the 1 second window has not expired, the second Ctrl+C
3941
triggers shutdown-first quit immediately.
4042
3. Otherwise, `ChatWidget` arms Ctrl+C and shows the quit hint (`ctrl + c again to quit`) for

0 commit comments

Comments
 (0)