Fix scrolling to negative offsets

This commit is contained in:
Anthony Sottile
2019-09-13 17:32:47 -07:00
parent 47e8aa0145
commit a0b7eb2f9c
2 changed files with 20 additions and 0 deletions

View File

@@ -61,6 +61,7 @@ class Position:
def maybe_scroll_up(self, margin: Margin) -> None:
if self.cursor_line < self.file_line:
self.file_line -= self._scroll_amount()
self.file_line = max(self.file_line, 0)
def up(self, margin: Margin, lines: List[str]) -> None:
if self.cursor_line > 0:

View File

@@ -385,6 +385,25 @@ def test_resize_scrolls_up(tmpdir):
assert h.screenshot().splitlines()[3] == 'line_7'
def test_resize_scroll_does_not_go_negative(tmpdir):
f = tmpdir.join('f')
f.write('\n'.join(f'line_{i}' for i in range(10)))
with run(str(f)) as h, and_exit(h):
for _ in range(5):
h.press('Down')
h.await_cursor_position(x=0, y=6)
with h.resize(80, 7):
h.await_text_missing('line_9')
h.await_text('line_9')
for _ in range(2):
h.press('Up')
assert h.screenshot().splitlines()[1] == 'line_0'
def test_very_narrow_window_status():
with run(height=50) as h, and_exit(h):
with h.resize(5, 50):