@@ -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// ============================================================================
0 commit comments