Skip to content

Visual Studio Code, rebuilt in Rust

Rust

fix(list): focus the last row when a page passes the list's end

rokartur4466defb6955
diff --git a/native/crates/app/src/list_tree.rs b/native/crates/app/src/list_tree.rs
index 48c505d05a9..820758b1d50 100644
--- a/native/crates/app/src/list_tree.rs
+++ b/native/crates/app/src/list_tree.rs
@@ -51,7 +51,8 @@ pub fn reveal_scroll_top(list: ListScroll, index: usize, center: bool) -> Option
pub fn page_focus(list: ListScroll, down: bool, focus: Option<usize>) -> Option<(usize, f32)> {
let ListScroll { count, row_height, viewport, scroll_top } = list;
let edge_row = |scroll_top: f32| -> usize {
- let index = |y: f32| ((y / row_height).floor() as usize).min(count - 1);
+ // rangeMap.ts `indexAt`: `count` past the last row.
+ let index = |y: f32| ((y / row_height).floor() as usize).min(count);
match down {
true => index(scroll_top + viewport).saturating_sub(1),
false if scroll_top <= 0. => 0,
diff --git a/native/crates/app/src/list_tree/tests.rs b/native/crates/app/src/list_tree/tests.rs
index 2b6f7248202..fc4310b69b4 100644
--- a/native/crates/app/src/list_tree/tests.rs
+++ b/native/crates/app/src/list_tree/tests.rs
@@ -17,6 +17,14 @@ fn a_sticky_row_is_pushed_up_by_the_end_of_its_children() {
assert_eq!(sticky_rows(&depths, 20., 60., 100., 1), []);
}
+/// listWidget.ts `focusNextPage`: a page past the list's end focuses its last row, a full page the row above the edge.
+#[test]
+fn page_down_focuses_the_last_row_on_the_page() {
+ let short = ListScroll { count: 3, row_height: 18., viewport: 100., scroll_top: 0. };
+ assert_eq!(page_focus(short, true, None), Some((2, 0.)));
+ let long = ListScroll { count: 20, row_height: 18., viewport: 90., scroll_top: 0. };
+ assert_eq!(page_focus(long, true, Some(0)), Some((4, 0.)));
+}
#[test]
fn nested_parents_stick_up_to_the_item_count_and_40_percent_of_the_view() {
// a/ b/ c/ with ten files in c, 22px rows.