fix: Improve display of added and deleted lines with proper formatting and positioning

This commit is contained in:
n loewen (aider) 2025-06-07 19:57:14 +01:00
parent 2954f16cfd
commit d76e5bdc17
1 changed files with 54 additions and 28 deletions

82
gtm
View File

@ -166,36 +166,62 @@ def main(stdscr, filename, show_additions=False, show_deletions=False):
# Draw file content (right pane) - more efficiently # Draw file content (right pane) - more efficiently
right_width = width - divider_col - 3 right_width = width - divider_col - 3
# First, collect all lines to display (regular and deleted)
display_lines = []
for i, line in enumerate(visible_lines): for i, line in enumerate(visible_lines):
# Only draw what fits in the window line_num = i + scroll_offset + 1 # 1-based line number
if i < height - 1:
line_num = i + scroll_offset + 1 # 1-based line number # Check if this is an added line
is_added = False
if show_additions:
for added_line_num, _ in added_lines:
if added_line_num == line_num:
is_added = True
break
# Add the regular line to our display list
display_lines.append({
'type': 'added' if is_added else 'regular',
'content': line,
'line_num': line_num
})
# If showing deletions, check if there are deleted lines at this position
if show_deletions:
for del_line_num, del_line_content in deleted_lines:
if del_line_num == line_num:
# Add the deleted line after the current line
display_lines.append({
'type': 'deleted',
'content': del_line_content,
'line_num': line_num
})
# Now display all lines
display_row = 0
for line_info in display_lines:
# Stop if we've reached the bottom of the screen
if display_row >= height - 1:
break
# Check if this is an added line line_type = line_info['type']
is_added = False content = line_info['content']
if show_additions:
for added_line_num, _ in added_lines: if line_type == 'added':
if added_line_num == line_num: # Green with + prefix for added lines
is_added = True stdscr.addstr(display_row, divider_col + 2, "+ ", curses.color_pair(3))
break stdscr.addnstr(display_row, divider_col + 4, content, right_width - 2, curses.color_pair(3))
elif line_type == 'deleted':
# Display the line with appropriate formatting # Red with - prefix for deleted lines
if is_added: stdscr.addstr(display_row, divider_col + 2, "- ", curses.color_pair(4))
stdscr.addstr(i, divider_col + 2, "+ ", curses.color_pair(3)) stdscr.addnstr(display_row, divider_col + 4, content, right_width - 2, curses.color_pair(4))
stdscr.addnstr(i, divider_col + 4, line, right_width - 2, curses.color_pair(3)) else:
else: # Regular line
stdscr.addnstr(i, divider_col + 2, line, right_width) stdscr.addnstr(display_row, divider_col + 2, content, right_width)
# Display deleted lines if enabled display_row += 1
if show_deletions:
# Check if there are deleted lines after the current line
for del_line_num, del_line_content in deleted_lines:
if del_line_num == line_num:
# Only show if we have space
if i + 1 < height - 1:
i += 1 # Move to next line for displaying the deleted content
stdscr.addstr(i, divider_col + 2, "- ", curses.color_pair(4))
stdscr.addnstr(i, divider_col + 4, del_line_content, right_width - 2, curses.color_pair(4))
# Status bars for both panes # Status bars for both panes
visible_height = height - 1 # Reserve 1 line for the status bar visible_height = height - 1 # Reserve 1 line for the status bar