Skip to content

Commit

Permalink
Fix page_up and page_down bug in DataTable when show_header is False (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rj-lee authored Aug 21, 2023
1 parent 77e01b8 commit fc0b5cc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions src/textual/widgets/_data_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tests/test_data_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit fc0b5cc

Please sign in to comment.