Skip to content

Commit b0b3939

Browse files
committed
fix(tui): reset quit confirmation on esc
1 parent 7954d02 commit b0b3939

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/cortex-tui/src/app/methods.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ impl AppState {
165165

166166
/// Handle Ctrl+C press (double-tap to quit)
167167
pub fn handle_ctrl_c(&mut self) -> bool {
168+
self.reset_esc();
169+
168170
let now = Instant::now();
169171
if let Some(last) = self.last_ctrl_c
170172
&& now.duration_since(last) < Duration::from_millis(500)
@@ -183,6 +185,8 @@ impl AppState {
183185

184186
/// Handle ESC press (double-tap to quit when idle)
185187
pub fn handle_esc(&mut self) -> bool {
188+
self.reset_ctrl_c();
189+
186190
let now = Instant::now();
187191
if let Some(last) = self.last_esc
188192
&& now.duration_since(last) < Duration::from_millis(500)
@@ -200,6 +204,39 @@ impl AppState {
200204
}
201205
}
202206

207+
#[cfg(test)]
208+
mod tests {
209+
use super::AppState;
210+
211+
#[test]
212+
fn test_esc_resets_ctrl_c_quit_confirmation() {
213+
let mut app_state = AppState::new();
214+
215+
assert!(!app_state.handle_ctrl_c());
216+
assert!(app_state.last_ctrl_c.is_some());
217+
218+
assert!(!app_state.handle_esc());
219+
assert!(app_state.last_ctrl_c.is_none());
220+
221+
assert!(!app_state.handle_ctrl_c());
222+
assert!(!app_state.should_quit());
223+
}
224+
225+
#[test]
226+
fn test_ctrl_c_resets_esc_quit_confirmation() {
227+
let mut app_state = AppState::new();
228+
229+
assert!(!app_state.handle_esc());
230+
assert!(app_state.last_esc.is_some());
231+
232+
assert!(!app_state.handle_ctrl_c());
233+
assert!(app_state.last_esc.is_none());
234+
235+
assert!(!app_state.handle_esc());
236+
assert!(!app_state.should_quit());
237+
}
238+
}
239+
203240
// ============================================================================
204241
// APPSTATE METHODS - Modals
205242
// ============================================================================

src/cortex-tui/src/runner/event_loop/input.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ impl EventLoop {
367367

368368
/// Handle ESC key with double-tap to quit
369369
fn handle_esc(&mut self, terminal: &mut CortexTerminal) -> Result<()> {
370+
self.app_state.reset_ctrl_c();
371+
370372
// Priority 1: If viewing a subagent conversation, return to main conversation
371373
if self.app_state.is_viewing_subagent() {
372374
self.app_state.return_to_main_conversation();

0 commit comments

Comments
 (0)