refactor: Simplify Escape key handling with single state update
This commit is contained in:
parent
e525aef5c2
commit
a17a515062
19
gtm
19
gtm
|
|
@ -1324,14 +1324,21 @@ def handle_keyboard_input(key, state: AppState) -> AppState:
|
||||||
|
|
||||||
# Handle Escape key immediately for search results
|
# Handle Escape key immediately for search results
|
||||||
if key == 27: # Escape key
|
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:
|
if state.search_mode:
|
||||||
return replace(state, search_mode=False)
|
new_state = replace(new_state, search_mode=False)
|
||||||
elif state.show_help:
|
|
||||||
return replace(state, show_help=False)
|
|
||||||
elif state.is_selecting:
|
elif state.is_selecting:
|
||||||
return replace(state, is_selecting=False, selection_start_coord=None, selection_end_coord=None)
|
new_state = replace(new_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)
|
# Return the updated state with all changes
|
||||||
|
return new_state
|
||||||
|
|
||||||
# If in search mode, handle search input
|
# If in search mode, handle search input
|
||||||
if state.search_mode:
|
if state.search_mode:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue