From a17a515062ae0ca29d05509cb9baa20ff62c1fa0 Mon Sep 17 00:00:00 2001 From: "n loewen (aider)" Date: Sun, 8 Jun 2025 10:19:21 +0100 Subject: [PATCH] refactor: Simplify Escape key handling with single state update --- gtm | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/gtm b/gtm index bc3ef2c..89dab67 100755 --- a/gtm +++ b/gtm @@ -1324,14 +1324,21 @@ def handle_keyboard_input(key, state: AppState) -> AppState: # Handle Escape key immediately for search results if key == 27: # Escape key + # Create a new state with all escape-related changes + new_state = state + + # Clear search results + if state.search_matches: + new_state = replace(new_state, search_matches=[], current_match_idx=-1) + + # Handle other Escape actions if state.search_mode: - return replace(state, search_mode=False) - elif state.show_help: - return replace(state, show_help=False) + new_state = replace(new_state, search_mode=False) elif state.is_selecting: - return replace(state, is_selecting=False, selection_start_coord=None, selection_end_coord=None) - elif state.search_matches: # Clear active search results - return replace(state, search_matches=[], current_match_idx=-1) + new_state = replace(new_state, is_selecting=False, selection_start_coord=None, selection_end_coord=None) + + # Return the updated state with all changes + return new_state # If in search mode, handle search input if state.search_mode: