refactor: Improve Escape key responsiveness in keyboard input handling
This commit is contained in:
parent
b25bf2d16a
commit
394f188b72
22
gtm
22
gtm
|
|
@ -1322,11 +1322,20 @@ def handle_keyboard_input(key, state: AppState) -> AppState:
|
|||
if state.show_help:
|
||||
return replace(state, show_help=False)
|
||||
|
||||
# Handle Escape key immediately for search results
|
||||
if key == 27: # Escape key
|
||||
if state.search_mode:
|
||||
return replace(state, search_mode=False)
|
||||
elif state.show_help:
|
||||
return replace(state, show_help=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)
|
||||
|
||||
# If in search mode, handle search input
|
||||
if state.search_mode:
|
||||
if key == 27: # Escape key - exit search mode
|
||||
return replace(state, search_mode=False)
|
||||
elif key == 10 or key == 13: # Enter key - perform search
|
||||
if key == 10 or key == 13: # Enter key - perform search
|
||||
new_state = perform_search(state)
|
||||
return replace(new_state, search_mode=False)
|
||||
elif key == 8 or key == 127 or key == curses.KEY_BACKSPACE: # Backspace
|
||||
|
|
@ -1342,13 +1351,6 @@ def handle_keyboard_input(key, state: AppState) -> AppState:
|
|||
# Normal mode key handling
|
||||
if key in [ord('q')]:
|
||||
return replace(state, should_exit=True)
|
||||
elif key == 27: # Escape key
|
||||
if state.show_help:
|
||||
return replace(state, show_help=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)
|
||||
elif key == ord('?'): # Toggle help popup
|
||||
return replace(state, show_help=not state.show_help)
|
||||
elif key == ord('/'): # Start search
|
||||
|
|
|
|||
Loading…
Reference in New Issue