feat: Implement line-by-line selection with real-time visual feedback
This commit is contained in:
parent
8156da7632
commit
141e69547c
26
gtm2.py
26
gtm2.py
|
|
@ -278,11 +278,18 @@ def draw_selection(stdscr, state):
|
||||||
return
|
return
|
||||||
|
|
||||||
start_x, start_y = state.selection_start_coord
|
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)
|
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):
|
for y in range(y1, y2 + 1):
|
||||||
try:
|
try:
|
||||||
# chgat can fail at the bottom-right corner of the screen
|
# chgat can fail at the bottom-right corner of the screen
|
||||||
|
|
@ -350,19 +357,26 @@ def copy_selection_to_clipboard(stdscr, state):
|
||||||
return
|
return
|
||||||
|
|
||||||
start_x, start_y = state.selection_start_coord
|
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)
|
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()
|
height, width = stdscr.getmaxyx()
|
||||||
selected_text_parts = []
|
selected_text_parts = []
|
||||||
|
|
||||||
for y in range(y1, y2 + 1):
|
for y in range(y1, y2 + 1):
|
||||||
if 0 <= y < height:
|
if 0 <= y < height:
|
||||||
line_str = ""
|
line_str = ""
|
||||||
for x in range(x1, x2 + 1):
|
end_col = min(x2, width - 1)
|
||||||
if 0 <= x < width:
|
for x in range(x1, end_col + 1):
|
||||||
try:
|
try:
|
||||||
char_and_attr = stdscr.inch(y, x)
|
char_and_attr = stdscr.inch(y, x)
|
||||||
char = char_and_attr & 0xFF
|
char = char_and_attr & 0xFF
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue