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:
@@ -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.));
|
||||
});
|
||||
|
||||
@@ -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.),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user