From 65d35c1d733020af5a438e6ad923dd1e34355bcc Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 21 Aug 2024 13:55:17 +0100 Subject: [PATCH 1/5] snapshot --- CHANGELOG.md | 1 + src/textual/widget.py | 8 ++++---- .../snapshot_tests/snapshot_apps/scroll_page.py | 17 +++++++++++++++++ tests/snapshot_tests/test_snapshots.py | 5 +++++ 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 tests/snapshot_tests/snapshot_apps/scroll_page.py diff --git a/CHANGELOG.md b/CHANGELOG.md index f49737faed..d284113a85 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 ## [0.76.0] diff --git a/src/textual/widget.py b/src/textual/widget.py index 0668e3bbc8..43c543424e 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.size.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.size.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.size.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.size.width, animate=animate, speed=speed, duration=duration, 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..2b291d334a --- /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 = os.environ.get("SUFFIX", "A" * 1000) + for i in range(1, 1000): + 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..be298bb638 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -1448,3 +1448,8 @@ 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""" + assert snap_compare(SNAPSHOT_APPS_DIR / "scroll_page.py", press=["pagedown"]) From 1ed1dca251c14f99c630e3e40d146a3e041d39b7 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 21 Aug 2024 13:59:55 +0100 Subject: [PATCH 2/5] test and snapshot --- .../test_snapshots/test_scroll_page_down.svg | 156 ++++++++++++++++++ .../snapshot_apps/scroll_page.py | 2 +- tests/snapshot_tests/test_snapshots.py | 5 +- 3 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 tests/snapshot_tests/__snapshots__/test_snapshots/test_scroll_page_down.svg 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..1510bad1e2 --- /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 index 2b291d334a..61e91dbe4d 100644 --- a/tests/snapshot_tests/snapshot_apps/scroll_page.py +++ b/tests/snapshot_tests/snapshot_apps/scroll_page.py @@ -6,7 +6,7 @@ class RichLogTest(App): def compose(self): ri = RichLog(auto_scroll=False) - suffix = os.environ.get("SUFFIX", "A" * 1000) + suffix = "A" * 1000 for i in range(1, 1000): ri.write(f"This is line number {i} {suffix}") yield ri diff --git a/tests/snapshot_tests/test_snapshots.py b/tests/snapshot_tests/test_snapshots.py index be298bb638..9d7a996242 100644 --- a/tests/snapshot_tests/test_snapshots.py +++ b/tests/snapshot_tests/test_snapshots.py @@ -1452,4 +1452,7 @@ def test_split(snap_compare): def test_scroll_page_down(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/4914""" - assert snap_compare(SNAPSHOT_APPS_DIR / "scroll_page.py", press=["pagedown"]) + # Should show 25 at the top + assert snap_compare( + SNAPSHOT_APPS_DIR / "scroll_page.py", press=["pagedown"], terminal_size=(80, 25) + ) From 7f8f912a37ece23775bf0ecd6fec782991e7bb68 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 21 Aug 2024 14:00:41 +0100 Subject: [PATCH 3/5] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d284113a85..094abde911 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +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 +- Fixed scrolling by page not taking scrollbar in to account https://github.com/Textualize/textual/pull/4916 ## [0.76.0] From a71088ea828ddba0c133ffd2748d290cadb0eff1 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 21 Aug 2024 15:21:02 +0100 Subject: [PATCH 4/5] simplify --- src/textual/widget.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/textual/widget.py b/src/textual/widget.py index 43c543424e..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.scrollable_content_region.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.scrollable_content_region.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.scrollable_content_region.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.scrollable_content_region.size.width, + x=self.scroll_x + self.scrollable_content_region.width, animate=animate, speed=speed, duration=duration, From fea0bce8ef0515abc669453d78615179febe5641 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Thu, 22 Aug 2024 10:48:37 +0100 Subject: [PATCH 5/5] reduce sanapshot size --- .../test_snapshots/test_scroll_page_down.svg | 120 +++++++++--------- .../snapshot_apps/scroll_page.py | 4 +- 2 files changed, 62 insertions(+), 62 deletions(-) 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 index 1510bad1e2..1e029dc3d3 100644 --- a/tests/snapshot_tests/__snapshots__/test_snapshots/test_scroll_page_down.svg +++ b/tests/snapshot_tests/__snapshots__/test_snapshots/test_scroll_page_down.svg @@ -19,138 +19,138 @@ font-weight: 700; } - .terminal-3094950062-matrix { + .terminal-1763864944-matrix { font-family: Fira Code, monospace; font-size: 20px; line-height: 24.4px; font-variant-east-asian: full-width; } - .terminal-3094950062-title { + .terminal-1763864944-title { font-size: 18px; font-weight: bold; font-family: arial; } - .terminal-3094950062-r1 { fill: #e1e1e1 } -.terminal-3094950062-r2 { fill: #23568b } -.terminal-3094950062-r3 { fill: #c5c8c6 } -.terminal-3094950062-r4 { fill: #14191f } + .terminal-1763864944-r1 { fill: #e1e1e1 } +.terminal-1763864944-r2 { fill: #c5c8c6 } +.terminal-1763864944-r3 { fill: #23568b } +.terminal-1763864944-r4 { fill: #14191f } - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - RichLogTest + 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 - + + + + 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 index 61e91dbe4d..33243fef5c 100644 --- a/tests/snapshot_tests/snapshot_apps/scroll_page.py +++ b/tests/snapshot_tests/snapshot_apps/scroll_page.py @@ -6,8 +6,8 @@ class RichLogTest(App): def compose(self): ri = RichLog(auto_scroll=False) - suffix = "A" * 1000 - for i in range(1, 1000): + suffix = "A" * 100 + for i in range(1, 100): ri.write(f"This is line number {i} {suffix}") yield ri