From 4fb2c353df7f029ad07ddbcc8535a2072aff461f Mon Sep 17 00:00:00 2001 From: "n loewen (aider)" Date: Sat, 7 Jun 2025 22:35:11 +0100 Subject: [PATCH] fix: Improve selection mode handling with mouse and escape key --- gtm2.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/gtm2.py b/gtm2.py index e988878..e8a00b8 100755 --- a/gtm2.py +++ b/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')]: