From fc0b5ccf9a37bd477a8e11fa9e2f9d154c87e409 Mon Sep 17 00:00:00 2001 From: Ren Jian Lee <47578853+rj-lee@users.noreply.github.com> Date: Mon, 21 Aug 2023 10:30:40 -0500 Subject: [PATCH] Fix page_up and page_down bug in DataTable when show_header is False (#3093) --- CHANGELOG.md | 2 ++ src/textual/widgets/_data_table.py | 10 ++++------ tests/test_data_table.py | 4 +++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 176379eae7..91cfab5c49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +- Fixed `page_up` and `page_down` bug in `DataTable` when `show_header = False` https://github.com/Textualize/textual/pull/3093 + ### Changed - grid-columns and grid-rows now accept an `auto` token to detect the optimal size https://github.com/Textualize/textual/pull/3107 diff --git a/src/textual/widgets/_data_table.py b/src/textual/widgets/_data_table.py index db3b2801d4..6201983dd6 100644 --- a/src/textual/widgets/_data_table.py +++ b/src/textual/widgets/_data_table.py @@ -2205,9 +2205,8 @@ async def _on_click(self, event: events.Click) -> None: def action_page_down(self) -> None: """Move the cursor one page down.""" self._set_hover_cursor(False) - cursor_type = self.cursor_type - if self.show_cursor and (cursor_type == "cell" or cursor_type == "row"): - height = self.size.height - self.header_height if self.show_header else 0 + if self.show_cursor and self.cursor_type in ("cell", "row"): + height = self.size.height - (self.header_height if self.show_header else 0) # Determine how many rows constitutes a "page" offset = 0 @@ -2228,9 +2227,8 @@ def action_page_down(self) -> None: def action_page_up(self) -> None: """Move the cursor one page up.""" self._set_hover_cursor(False) - cursor_type = self.cursor_type - if self.show_cursor and (cursor_type == "cell" or cursor_type == "row"): - height = self.size.height - self.header_height if self.show_header else 0 + if self.show_cursor and self.cursor_type in ("cell", "row"): + height = self.size.height - (self.header_height if self.show_header else 0) # Determine how many rows constitutes a "page" offset = 0 diff --git a/tests/test_data_table.py b/tests/test_data_table.py index a1c08edc7c..e00b9432a4 100644 --- a/tests/test_data_table.py +++ b/tests/test_data_table.py @@ -173,11 +173,13 @@ async def test_empty_table_interactions(): assert app.message_names == [] -async def test_cursor_movement_with_home_pagedown_etc(): +@pytest.mark.parametrize("show_header", [True, False]) +async def test_cursor_movement_with_home_pagedown_etc(show_header): app = DataTableApp() async with app.run_test() as pilot: table = app.query_one(DataTable) + table.show_header = show_header table.add_columns("A", "B") table.add_rows(ROWS) await pilot.press("right", "pagedown")