fix: Improve display of added and deleted lines with proper formatting and positioning
This commit is contained in:
parent
2954f16cfd
commit
d76e5bdc17
56
gtm
56
gtm
|
|
@ -166,9 +166,11 @@ 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
|
|
||||||
if i < height - 1:
|
|
||||||
line_num = i + scroll_offset + 1 # 1-based line number
|
line_num = i + scroll_offset + 1 # 1-based line number
|
||||||
|
|
||||||
# Check if this is an added line
|
# Check if this is an added line
|
||||||
|
|
@ -179,23 +181,47 @@ def main(stdscr, filename, show_additions=False, show_deletions=False):
|
||||||
is_added = True
|
is_added = True
|
||||||
break
|
break
|
||||||
|
|
||||||
# Display the line with appropriate formatting
|
# Add the regular line to our display list
|
||||||
if is_added:
|
display_lines.append({
|
||||||
stdscr.addstr(i, divider_col + 2, "+ ", curses.color_pair(3))
|
'type': 'added' if is_added else 'regular',
|
||||||
stdscr.addnstr(i, divider_col + 4, line, right_width - 2, curses.color_pair(3))
|
'content': line,
|
||||||
else:
|
'line_num': line_num
|
||||||
stdscr.addnstr(i, divider_col + 2, line, right_width)
|
})
|
||||||
|
|
||||||
# Display deleted lines if enabled
|
# If showing deletions, check if there are deleted lines at this position
|
||||||
if show_deletions:
|
if show_deletions:
|
||||||
# Check if there are deleted lines after the current line
|
|
||||||
for del_line_num, del_line_content in deleted_lines:
|
for del_line_num, del_line_content in deleted_lines:
|
||||||
if del_line_num == line_num:
|
if del_line_num == line_num:
|
||||||
# Only show if we have space
|
# Add the deleted line after the current line
|
||||||
if i + 1 < height - 1:
|
display_lines.append({
|
||||||
i += 1 # Move to next line for displaying the deleted content
|
'type': 'deleted',
|
||||||
stdscr.addstr(i, divider_col + 2, "- ", curses.color_pair(4))
|
'content': del_line_content,
|
||||||
stdscr.addnstr(i, divider_col + 4, del_line_content, right_width - 2, curses.color_pair(4))
|
'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
|
||||||
|
|
||||||
|
line_type = line_info['type']
|
||||||
|
content = line_info['content']
|
||||||
|
|
||||||
|
if line_type == 'added':
|
||||||
|
# Green with + prefix for added lines
|
||||||
|
stdscr.addstr(display_row, divider_col + 2, "+ ", curses.color_pair(3))
|
||||||
|
stdscr.addnstr(display_row, divider_col + 4, content, right_width - 2, curses.color_pair(3))
|
||||||
|
elif line_type == 'deleted':
|
||||||
|
# Red with - prefix for deleted lines
|
||||||
|
stdscr.addstr(display_row, divider_col + 2, "- ", curses.color_pair(4))
|
||||||
|
stdscr.addnstr(display_row, divider_col + 4, content, right_width - 2, curses.color_pair(4))
|
||||||
|
else:
|
||||||
|
# Regular line
|
||||||
|
stdscr.addnstr(display_row, divider_col + 2, content, right_width)
|
||||||
|
|
||||||
|
display_row += 1
|
||||||
|
|
||||||
# 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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue