fix: Preserve scroll position when switching commits in file view

This commit is contained in:
n loewen (aider) 2025-06-07 20:20:21 +01:00
parent 2df25ac089
commit af9c9f787e
1 changed files with 4 additions and 5 deletions

9
gtm
View File

@ -129,8 +129,8 @@ def main(stdscr, filename, show_whole_diff=False, show_additions=False, show_del
# Calculate current scroll position as percentage before changing commits
scroll_percentage = 0
if len(file_lines) > 0 and focus == "left" and key in [curses.KEY_DOWN, curses.KEY_UP, ord('j'), ord('k')]:
# Calculate current position as percentage before loading new file
if len(file_lines) > 0:
max_scroll = max(0, len(file_lines) - (height - 1))
if max_scroll > 0:
scroll_percentage = scroll_offset / max_scroll
@ -151,6 +151,8 @@ def main(stdscr, filename, show_whole_diff=False, show_additions=False, show_del
max_scroll = max(0, len(file_lines) - (height - 1))
if max_scroll > 0:
scroll_offset = int(scroll_percentage * max_scroll)
else:
scroll_offset = 0
# Recalculate max_scroll and ensure scroll_offset is within bounds
max_scroll = max(0, len(file_lines) - (height - 1))
@ -340,19 +342,16 @@ def main(stdscr, filename, show_whole_diff=False, show_additions=False, show_del
elif key in [curses.KEY_UP, ord('k')]:
if selected_commit > 0:
selected_commit -= 1
scroll_offset = 0
elif key in [curses.KEY_NPAGE, ord(' ')]:
# Page down in left pane
new_selected = min(selected_commit + height - 1, len(commits) - 1)
if new_selected != selected_commit:
selected_commit = new_selected
scroll_offset = 0
elif key in [curses.KEY_PPAGE, 8, 127, curses.KEY_SR]:
# Page up in left pane
new_selected = max(0, selected_commit - (height - 1))
if new_selected != selected_commit:
selected_commit = new_selected
scroll_offset = 0
# Right pane scrolling
elif focus == "right":