refactor: Simplify Escape key handling with single state update

This commit is contained in:
n loewen (aider) 2025-06-08 10:19:21 +01:00
parent e525aef5c2
commit a17a515062
1 changed files with 13 additions and 6 deletions

19
gtm
View File

@ -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: