fix: Improve selection mode handling with mouse and escape key
This commit is contained in:
parent
dc162e8dda
commit
4fb2c353df
22
gtm2.py
22
gtm2.py
|
|
@ -438,14 +438,23 @@ def handle_mouse_input(stdscr, state):
|
|||
state.last_bstate = bstate
|
||||
state.mouse_x, state.mouse_y = mx, my
|
||||
|
||||
# If selection is in progress, clicking anywhere should clear it
|
||||
if state.is_selecting and bstate & curses.BUTTON1_PRESSED:
|
||||
# If selection is in progress, any mouse event should clear it
|
||||
if state.is_selecting:
|
||||
state.is_selecting = False
|
||||
state.selection_start_coord = None
|
||||
state.selection_end_coord = None
|
||||
state.focus = "left" if mx < state.divider_col else "right"
|
||||
# Redraw immediately to clear selection highlight
|
||||
draw_ui(stdscr, state)
|
||||
|
||||
# If this was a new click, continue processing it
|
||||
if bstate & curses.BUTTON1_PRESSED:
|
||||
# Reset selection state and start a new selection
|
||||
state.is_selecting = True
|
||||
state.selection_start_coord = (mx, my)
|
||||
state.selection_end_coord = (mx, my)
|
||||
# Redraw immediately to show selection highlight as soon as it starts
|
||||
draw_ui(stdscr, state)
|
||||
return
|
||||
|
||||
# If a drag/selection is in progress
|
||||
|
|
@ -491,8 +500,15 @@ def handle_mouse_input(stdscr, state):
|
|||
pass
|
||||
|
||||
def handle_keyboard_input(key, state):
|
||||
if key in [ord('q'), 27]:
|
||||
if key in [ord('q')]:
|
||||
state.should_exit = True
|
||||
elif key == 27: # Escape key
|
||||
if state.is_selecting:
|
||||
state.is_selecting = False
|
||||
state.selection_start_coord = None
|
||||
state.selection_end_coord = None
|
||||
else:
|
||||
state.should_exit = True
|
||||
elif key == ord('m'):
|
||||
state.toggle_mouse()
|
||||
elif key in [curses.KEY_LEFT, ord('h')]:
|
||||
|
|
|
|||
Loading…
Reference in New Issue