diff options
author | Canop <cano.petrole@gmail.com> | 2020-07-23 16:24:44 +0200 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2020-07-23 16:24:44 +0200 |
commit | eb5f98c420a943c33e4cb8abfee964036014b016 (patch) | |
tree | 684640f635004566ce58722f0f54e4e8733bacbe /src/command | |
parent | 9eb2f8418830ebb4ab26331c7b5a13adc28e0c49 (diff) |
selected line in preview
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/scroll.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/command/scroll.rs b/src/command/scroll.rs index 2cfd8e9..0f3c448 100644 --- a/src/command/scroll.rs +++ b/src/command/scroll.rs @@ -6,11 +6,17 @@ pub enum ScrollCommand { } impl ScrollCommand { - pub fn to_lines(self, page_height: i32) -> i32 { + pub fn to_lines(self, page_height: usize) -> i32 { match self { Self::Lines(n) => n, - Self::Pages(n) => n * page_height, + Self::Pages(n) => n * page_height as i32, } } + /// compute the new scroll value + pub fn apply(self, scroll: usize, content_height: usize, page_height: usize) -> usize { + (scroll as i32 + self.to_lines(page_height)) + .min(content_height as i32 - page_height as i32 + 1) + .max(0) as usize + } } |