From 141e69547cd545c6517ee4b9c9adfa633b697900 Mon Sep 17 00:00:00 2001 From: "n loewen (aider)" Date: Sat, 7 Jun 2025 21:45:51 +0100 Subject: [PATCH] feat: Implement line-by-line selection with real-time visual feedback --- gtm2.py | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/gtm2.py b/gtm2.py index e9ca059..c89521e 100755 --- a/gtm2.py +++ b/gtm2.py @@ -278,11 +278,18 @@ def draw_selection(stdscr, state): return start_x, start_y = state.selection_start_coord - end_x, end_y = state.selection_end_coord + _, end_y = state.selection_end_coord - x1, x2 = min(start_x, end_x), max(start_x, end_x) y1, y2 = min(start_y, end_y), max(start_y, end_y) + # Determine pane from where selection started + pane = 'left' if start_x < state.divider_col else 'right' + + if pane == 'left': + x1, x2 = 0, state.divider_col - 1 + else: # right + x1, x2 = state.divider_col + 2, state.width - 1 + for y in range(y1, y2 + 1): try: # chgat can fail at the bottom-right corner of the screen @@ -350,25 +357,32 @@ def copy_selection_to_clipboard(stdscr, state): return start_x, start_y = state.selection_start_coord - end_x, end_y = state.selection_end_coord + _, end_y = state.selection_end_coord - x1, x2 = min(start_x, end_x), max(start_x, end_x) y1, y2 = min(start_y, end_y), max(start_y, end_y) + # Determine pane from where selection started + pane = 'left' if start_x < state.divider_col else 'right' + + if pane == 'left': + x1, x2 = 0, state.divider_col - 1 + else: # right + x1, x2 = state.divider_col + 2, state.width - 1 + height, width = stdscr.getmaxyx() selected_text_parts = [] for y in range(y1, y2 + 1): if 0 <= y < height: line_str = "" - for x in range(x1, x2 + 1): - if 0 <= x < width: - try: - char_and_attr = stdscr.inch(y, x) - char = char_and_attr & 0xFF - line_str += chr(char) - except curses.error: - line_str += " " + end_col = min(x2, width - 1) + for x in range(x1, end_col + 1): + try: + char_and_attr = stdscr.inch(y, x) + char = char_and_attr & 0xFF + line_str += chr(char) + except curses.error: + line_str += " " selected_text_parts.append(line_str.rstrip()) if selected_text_parts: