refactor: Improve mouse drag and selection event handling logic
This commit is contained in:
parent
f527ba4c36
commit
a0a5e722b3
54
gtm2.py
54
gtm2.py
|
|
@ -377,35 +377,39 @@ def handle_mouse_input(stdscr, state):
|
||||||
try:
|
try:
|
||||||
_, mx, my, _, bstate = curses.getmouse()
|
_, mx, my, _, bstate = curses.getmouse()
|
||||||
|
|
||||||
if bstate & curses.BUTTON1_PRESSED:
|
# If a drag/selection is in progress
|
||||||
# Only start a new action if no action is in progress
|
if state.is_selecting or state.dragging_divider:
|
||||||
if not state.dragging_divider and not state.is_selecting:
|
# Update coordinates for any event during drag
|
||||||
if abs(mx - state.divider_col) <= 1:
|
|
||||||
state.dragging_divider = True
|
|
||||||
else:
|
|
||||||
state.is_selecting = True
|
|
||||||
state.selection_start_coord = (mx, my)
|
|
||||||
state.selection_end_coord = (mx, my)
|
|
||||||
|
|
||||||
if state.dragging_divider:
|
|
||||||
state.update_divider(mx)
|
|
||||||
elif state.is_selecting:
|
|
||||||
state.selection_end_coord = (mx, my)
|
|
||||||
|
|
||||||
if bstate & curses.BUTTON1_RELEASED:
|
|
||||||
if state.dragging_divider:
|
if state.dragging_divider:
|
||||||
state.dragging_divider = False
|
state.update_divider(mx)
|
||||||
elif state.is_selecting:
|
elif state.is_selecting:
|
||||||
state.is_selecting = False
|
state.selection_end_coord = (mx, my)
|
||||||
start_x, start_y = state.selection_start_coord
|
|
||||||
|
|
||||||
if start_x == mx and start_y == my:
|
if bstate & curses.BUTTON1_RELEASED:
|
||||||
state.focus = "left" if mx < state.divider_col else "right"
|
# End of drag/selection
|
||||||
else:
|
if state.dragging_divider:
|
||||||
copy_selection_to_clipboard(stdscr, state)
|
state.dragging_divider = False
|
||||||
|
elif state.is_selecting:
|
||||||
|
# A simple click is a press and release at the same spot
|
||||||
|
if state.selection_start_coord == state.selection_end_coord:
|
||||||
|
state.focus = "left" if mx < state.divider_col else "right"
|
||||||
|
else:
|
||||||
|
# This was a drag, so copy the selection
|
||||||
|
copy_selection_to_clipboard(stdscr, state)
|
||||||
|
|
||||||
|
state.is_selecting = False
|
||||||
|
state.selection_start_coord = None
|
||||||
|
state.selection_end_coord = None
|
||||||
|
|
||||||
|
# If no drag/selection is in progress, check for a new one starting
|
||||||
|
elif bstate & curses.BUTTON1_PRESSED:
|
||||||
|
if abs(mx - state.divider_col) <= 1:
|
||||||
|
state.dragging_divider = True
|
||||||
|
else:
|
||||||
|
state.is_selecting = True
|
||||||
|
state.selection_start_coord = (mx, my)
|
||||||
|
state.selection_end_coord = (mx, my)
|
||||||
|
|
||||||
state.selection_start_coord = None
|
|
||||||
state.selection_end_coord = None
|
|
||||||
except curses.error:
|
except curses.error:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue