vim: Fix ctrl-u/ctrl-d (#3044)

- vim: Fix ctrl-d/ctrl-u to match vim (when :set scrolloff=3)
This commit is contained in:
Conrad Irwin
2023-09-27 07:48:50 -06:00
committed by GitHub
5 changed files with 122 additions and 21 deletions
+1 -1
View File
@@ -1429,7 +1429,7 @@ async fn test_scroll_page_up_page_down(cx: &mut gpui::TestAppContext) {
assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 3.));
editor.scroll_screen(&ScrollAmount::Page(-0.5), cx);
assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 2.));
assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 1.));
editor.scroll_screen(&ScrollAmount::Page(0.5), cx);
assert_eq!(editor.snapshot(cx).scroll_position(), vec2f(0., 3.));
});
+7 -3
View File
@@ -15,9 +15,13 @@ impl ScrollAmount {
Self::Line(count) => *count,
Self::Page(count) => editor
.visible_line_count()
// subtract one to leave an anchor line
// round towards zero (so page-up and page-down are symmetric)
.map(|l| (l * count).trunc() - count.signum())
.map(|mut l| {
// for full pages subtract one to leave an anchor line
if count.abs() == 1.0 {
l -= 1.0
}
(l * count).trunc()
})
.unwrap_or(0.),
}
}