Clamp scrolling to file contents

This commit is contained in:
n loewen 2025-04-23 22:04:40 +01:00
parent c2ef9f47e8
commit 29f0e7a28b
1 changed files with 3 additions and 2 deletions

View File

@ -76,12 +76,13 @@ def main(stdscr, filename):
elif focus == "right": elif focus == "right":
if key == curses.KEY_DOWN or key == ord('j'): if key == curses.KEY_DOWN or key == ord('j'):
if scroll_offset < max(0, len(file_lines) - height):
scroll_offset += 1 scroll_offset += 1
elif key == curses.KEY_UP or key == ord('k'): elif key == curses.KEY_UP or key == ord('k'):
if scroll_offset > 0: if scroll_offset > 0:
scroll_offset -= 1 scroll_offset -= 1
elif key == curses.KEY_NPAGE: # Page Down elif key == curses.KEY_NPAGE: # Page Down
scroll_offset += height scroll_offset = min(scroll_offset + height, max(0, len(file_lines) - height))
elif key == curses.KEY_PPAGE: # Page Up elif key == curses.KEY_PPAGE: # Page Up
scroll_offset = max(0, scroll_offset - height) scroll_offset = max(0, scroll_offset - height)