vim: Fix ctrl-b not moving the cursor (#17808)

Closes #17687

Release Notes:

- Fixed `ctrl-b` not moving the cursor.

---------

Co-authored-by: Abdelhakim Qbaich <abdelhakim@qbaich.com>
Co-authored-by: Pete LeVasseur <plevasseur@gmail.com>
This commit is contained in:
Thorsten Ball
2024-09-16 15:01:20 +02:00
committed by GitHub
co-authored by Abdelhakim Qbaich Pete LeVasseur
parent f986513d0d
commit e3d54b2211
3 changed files with 136 additions and 9 deletions
+28 -1
View File
@@ -1,6 +1,18 @@
use serde::Deserialize;
use ui::{px, Pixels};
#[derive(Debug)]
pub enum ScrollDirection {
Upwards,
Downwards,
}
impl ScrollDirection {
pub fn is_upwards(&self) -> bool {
matches!(self, ScrollDirection::Upwards)
}
}
#[derive(Debug, Clone, PartialEq, Deserialize)]
pub enum ScrollAmount {
// Scroll N lines (positive is towards the end of the document)
@@ -15,7 +27,7 @@ impl ScrollAmount {
Self::Line(count) => *count,
Self::Page(count) => {
// for full pages subtract one to leave an anchor line
if count.abs() == 1.0 {
if self.is_full_page() {
visible_line_count -= 1.0
}
(visible_line_count * count).trunc()
@@ -29,4 +41,19 @@ impl ScrollAmount {
ScrollAmount::Page(x) => px(height.0 * x),
}
}
pub fn is_full_page(&self) -> bool {
match self {
ScrollAmount::Page(count) if count.abs() == 1.0 => true,
_ => false,
}
}
pub fn direction(&self) -> ScrollDirection {
match self {
Self::Line(amount) if amount.is_sign_positive() => ScrollDirection::Downwards,
Self::Page(amount) if amount.is_sign_positive() => ScrollDirection::Downwards,
_ => ScrollDirection::Upwards,
}
}
}