diff --git a/gtm2.py b/gtm2.py index 175a4b5..e988878 100755 --- a/gtm2.py +++ b/gtm2.py @@ -438,31 +438,24 @@ 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: + 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) + return + # If a drag/selection is in progress - if state.is_selecting or state.dragging_divider: + if state.dragging_divider: # Update coordinates for any event during drag - if state.dragging_divider: - state.update_divider(mx) - elif state.is_selecting: - state.selection_end_coord = (mx, my) - # Redraw immediately to show selection highlight during drag - draw_ui(stdscr, state) - + state.update_divider(mx) + if bstate & curses.BUTTON1_RELEASED: - # End of drag/selection - if state.dragging_divider: - 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 + # 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: @@ -474,6 +467,25 @@ def handle_mouse_input(stdscr, state): state.selection_end_coord = (mx, my) # Redraw immediately to show selection highlight as soon as it starts draw_ui(stdscr, state) + + # 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) + + if bstate & curses.BUTTON1_RELEASED: + # End of selection + # 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 except curses.error: pass