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 // subtract one to leave an anchor line
19 // round towards zero (so page-up and page-down are symmetric)
20 .map(|l| (l * count).trunc() - count.signum())
21 .unwrap_or(0.),
22 }
23 }
24}