Fix page_up and page_down bug in DataTable when show_header is False (#3093)

This commit is contained in:
Ren Jian Lee
2023-08-21 10:30:40 -05:00
committed by GitHub
parent 77e01b8927
commit fc0b5ccf9a
3 changed files with 9 additions and 7 deletions

View File

@@ -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

View File

@@ -2205,9 +2205,8 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
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 @@ class DataTable(ScrollView, Generic[CellType], can_focus=True):
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

View File

@@ -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")