fix: Improve mouse click handling for pane switching
This commit is contained in:
parent
a035a350d4
commit
b0a142e90c
76
gtm2.py
76
gtm2.py
|
|
@ -121,6 +121,7 @@ class AppState:
|
||||||
self.is_selecting = False
|
self.is_selecting = False
|
||||||
self.selection_start_coord = None
|
self.selection_start_coord = None
|
||||||
self.selection_end_coord = None
|
self.selection_end_coord = None
|
||||||
|
self.click_position = None # Store click position to detect clicks vs. drags
|
||||||
self.last_bstate = 0
|
self.last_bstate = 0
|
||||||
self.mouse_x = -1
|
self.mouse_x = -1
|
||||||
self.mouse_y = -1
|
self.mouse_y = -1
|
||||||
|
|
@ -442,63 +443,58 @@ 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, only end it on mouse button release or press
|
# Handle mouse button press
|
||||||
if state.is_selecting and (bstate & curses.BUTTON1_RELEASED or bstate & curses.BUTTON1_PRESSED):
|
|
||||||
# End the current selection
|
|
||||||
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, start a new selection
|
|
||||||
if bstate & curses.BUTTON1_PRESSED:
|
if bstate & curses.BUTTON1_PRESSED:
|
||||||
state.is_selecting = True
|
# Check if clicking near divider
|
||||||
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
|
|
||||||
if state.dragging_divider:
|
|
||||||
# Update coordinates for any event during drag
|
|
||||||
state.update_divider(mx)
|
|
||||||
|
|
||||||
if bstate & curses.BUTTON1_RELEASED:
|
|
||||||
# End of drag
|
|
||||||
state.dragging_divider = False
|
|
||||||
|
|
||||||
# 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:
|
if abs(mx - state.divider_col) <= 1:
|
||||||
state.dragging_divider = True
|
state.dragging_divider = True
|
||||||
else:
|
else:
|
||||||
|
# Start a new selection
|
||||||
state.is_selecting = True
|
state.is_selecting = True
|
||||||
state.selection_start_coord = (mx, my)
|
state.selection_start_coord = (mx, my)
|
||||||
state.selection_end_coord = (mx, my)
|
state.selection_end_coord = (mx, my)
|
||||||
# Redraw immediately to show selection highlight as soon as it starts
|
# Store the click position for later comparison
|
||||||
draw_ui(stdscr, state)
|
state.click_position = (mx, my)
|
||||||
|
# Redraw immediately to show selection highlight
|
||||||
# Update selection end coordinates during drag
|
|
||||||
elif state.is_selecting:
|
|
||||||
state.selection_end_coord = (mx, my)
|
|
||||||
# Redraw immediately to show selection highlight during drag
|
|
||||||
draw_ui(stdscr, state)
|
draw_ui(stdscr, state)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Handle mouse button release
|
||||||
if bstate & curses.BUTTON1_RELEASED:
|
if bstate & curses.BUTTON1_RELEASED:
|
||||||
|
# End of divider drag
|
||||||
|
if state.dragging_divider:
|
||||||
|
state.dragging_divider = False
|
||||||
|
return
|
||||||
|
|
||||||
# End of selection
|
# End of selection
|
||||||
# A simple click is a press and release at the same spot
|
if state.is_selecting:
|
||||||
if state.selection_start_coord == state.selection_end_coord:
|
# Check if this was a click (press and release at same position)
|
||||||
|
# or very close to the same position (within 1-2 pixels)
|
||||||
|
if (state.click_position and
|
||||||
|
abs(state.click_position[0] - mx) <= 2 and
|
||||||
|
abs(state.click_position[1] - my) <= 2):
|
||||||
|
# This was a click, so switch panes
|
||||||
state.focus = "left" if mx < state.divider_col else "right"
|
state.focus = "left" if mx < state.divider_col else "right"
|
||||||
else:
|
elif state.selection_start_coord and state.selection_end_coord:
|
||||||
# This was a drag, so copy the selection
|
# This was a drag selection, copy the text
|
||||||
copy_selection_to_clipboard(stdscr, state)
|
copy_selection_to_clipboard(stdscr, state)
|
||||||
|
|
||||||
|
# Reset selection state
|
||||||
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.click_position = None
|
||||||
|
return
|
||||||
|
|
||||||
|
# Handle mouse movement during drag operations
|
||||||
|
if state.dragging_divider:
|
||||||
|
# Update divider position during drag
|
||||||
|
state.update_divider(mx)
|
||||||
|
elif state.is_selecting:
|
||||||
|
# Update selection end coordinates during drag
|
||||||
|
state.selection_end_coord = (mx, my)
|
||||||
|
# Redraw immediately to show selection highlight during drag
|
||||||
|
draw_ui(stdscr, state)
|
||||||
|
|
||||||
except curses.error:
|
except curses.error:
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue