1use crate::Editor;
2use serde::Deserialize;
3
4#[derive(Clone, PartialEq, Deserialize)]
5pub enum ScrollAmount {
6 // Scroll N lines (positive is towards the end of the document)
7 Line(f32),
8 // Scroll N pages (positive is towards the end of the document)
9 Page(f32),
10}
11
12impl ScrollAmount {
13 pub fn lines(&self, editor: &mut Editor) -> f32 {
14 match self {
15 Self::Line(count) => *count,
16 Self::Page(count) => editor
17 .visible_line_count()
18 .map(|mut l| {
19 // for full pages subtract one to leave an anchor line
20 if count.abs() == 1.0 {
21 l -= 1.0
22 }
23 (l * count).trunc()
24 })
25 .unwrap_or(0.),
26 }
27 }
28}