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.last_bstate = bstate
|
||||||
state.mouse_x, state.mouse_y = mx, my
|
state.mouse_x, state.mouse_y = mx, my
|
||||||
|
|
||||||
# If selection is in progress, clicking anywhere should clear it
|
# If selection is in progress, any mouse event should clear it
|
||||||
if state.is_selecting and bstate & curses.BUTTON1_PRESSED:
|
if state.is_selecting:
|
||||||
state.is_selecting = False
|
state.is_selecting = False
|
||||||
state.selection_start_coord = None
|
state.selection_start_coord = None
|
||||||
state.selection_end_coord = None
|
state.selection_end_coord = None
|
||||||
state.focus = "left" if mx < state.divider_col else "right"
|
state.focus = "left" if mx < state.divider_col else "right"
|
||||||
# Redraw immediately to clear selection highlight
|
# Redraw immediately to clear selection highlight
|
||||||
draw_ui(stdscr, state)
|
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
|
return
|
||||||
|
|
||||||
# If a drag/selection is in progress
|
# If a drag/selection is in progress
|
||||||
|
|
@ -491,7 +500,14 @@ def handle_mouse_input(stdscr, state):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def handle_keyboard_input(key, state):
|
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
|
state.should_exit = True
|
||||||
elif key == ord('m'):
|
elif key == ord('m'):
|
||||||
state.toggle_mouse()
|
state.toggle_mouse()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue