fix: page up and down stop at the table edges instead of wrapping
A page is 20 rows and the index wrapped modulo one less than the row count, so the last row was unreachable by paging, 21-row and 5-row tables did nothing on page down from the first row, and 4-row tables cycled 0, 2, 1 and never reached row 3. Page down now clamps to the last row and page up clamps to the first. With no division left, a single-row table is safe, so the early return only guards the empty table again, matching scroll_to_top and scroll_to_bottom.
This commit is contained in:
4 files changed
+166
-47
No files matched your search
@@ -171,10 +171,19 @@ mod property_tests {
|
||||
table.set_items(movies);
|
||||
|
||||
for i in 0..page_ops {
|
||||
let previous_index = table.state.selected().unwrap();
|
||||
|
||||
if i % 2 == 0 {
|
||||
table.page_down();
|
||||
|
||||
prop_assert_eq!(
|
||||
table.state.selected(),
|
||||
Some((previous_index + 20).min(list_size - 1))
|
||||
);
|
||||
} else {
|
||||
table.page_up();
|
||||
|
||||
prop_assert_eq!(table.state.selected(), Some(previous_index.saturating_sub(20)));
|
||||
}
|
||||
|
||||
let current = table.current_selection();
|
||||
|
||||
Reference in new issue
Block a user