diff --git a/CHANGELOG.md b/CHANGELOG.md index f49737faed..094abde911 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix crash when `validate_on` value isn't a set https://github.com/Textualize/textual/pull/4868 - Fix `Input.cursor_blink` having no effect on the blink cycle after mounting https://github.com/Textualize/textual/pull/4869 +- Fixed scrolling by page not taking scrollbar in to account https://github.com/Textualize/textual/pull/4916 ## [0.76.0] diff --git a/src/textual/widget.py b/src/textual/widget.py index 0668e3bbc8..868f39b6f2 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -2647,7 +2647,7 @@ def scroll_page_up( level: Minimum level required for the animation to take place (inclusive). """ self.scroll_to( - y=self.scroll_y - self.container_size.height, + y=self.scroll_y - self.scrollable_content_region.height, animate=animate, speed=speed, duration=duration, @@ -2680,7 +2680,7 @@ def scroll_page_down( level: Minimum level required for the animation to take place (inclusive). """ self.scroll_to( - y=self.scroll_y + self.container_size.height, + y=self.scroll_y + self.scrollable_content_region.height, animate=animate, speed=speed, duration=duration, @@ -2715,7 +2715,7 @@ def scroll_page_left( if speed is None and duration is None: duration = 0.3 self.scroll_to( - x=self.scroll_x - self.container_size.width, + x=self.scroll_x - self.scrollable_content_region.width, animate=animate, speed=speed, duration=duration, @@ -2750,7 +2750,7 @@ def scroll_page_right( if speed is None and duration is None: duration = 0.3 self.scroll_to( - x=self.scroll_x + self.container_size.width, + x=self.scroll_x + self.scrollable_content_region.width, animate=animate, speed=speed, duration=duration, diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots/test_scroll_page_down.svg b/tests/snapshot_tests/__snapshots__/test_snapshots/test_scroll_page_down.svg new file mode 100644 index 0000000000..1e029dc3d3 --- /dev/null +++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_scroll_page_down.svg @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + RichLogTest + + + + + + + + + + This is line number 25 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 26 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 27 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 28 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 29 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 30 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA▂▂ +This is line number 31 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 32 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 33 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 34 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 35 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 36 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA▃▃ +This is line number 37 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 38 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 39 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 40 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 41 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 42 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 43 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 44 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 45 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 46 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 47 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +This is line number 48 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + + + + diff --git a/tests/snapshot_tests/snapshot_apps/scroll_page.py b/tests/snapshot_tests/snapshot_apps/scroll_page.py new file mode 100644 index 0000000000..33243fef5c --- /dev/null +++ b/tests/snapshot_tests/snapshot_apps/scroll_page.py @@ -0,0 +1,17 @@ +import os +from textual.app import App +from textual.widgets import RichLog + + +class RichLogTest(App): + def compose(self): + ri = RichLog(auto_scroll=False) + suffix = "A" * 100 + for i in range(1, 100): + ri.write(f"This is line number {i} {suffix}") + yield ri + + +if __name__ == "__main__": + app = RichLogTest() + app.run() diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index 82c131c954..9d7a996242 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -1448,3 +1448,11 @@ def test_command_palette_key_change(snap_compare): def test_split(snap_compare): """Test split rule.""" assert snap_compare(SNAPSHOT_APPS_DIR / "split.py", terminal_size=(100, 30)) + + +def test_scroll_page_down(snap_compare): + """Regression test for https://github.com/Textualize/textual/issues/4914""" + # Should show 25 at the top + assert snap_compare( + SNAPSHOT_APPS_DIR / "scroll_page.py", press=["pagedown"], terminal_size=(80, 25) + )