feat: Implement line-by-line selection with real-time visual feedback
This commit is contained in:
parent
8156da7632
commit
141e69547c
38
gtm2.py
38
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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue