diff --git a/src/menu.rs b/src/menu.rs index 6b1c4b4..2caaea3 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -308,9 +308,8 @@ impl Menu { // how many rows to pad with blank lines at the end of the page fn padding_bottom(&self) -> usize { let padding = (self.rows() as f64 * 0.75) as usize; - let lines = self.lines.len(); - if lines > padding { - lines - padding + if self.lines.len() > padding { + self.lines.len() - padding } else { 0 } diff --git a/src/text.rs b/src/text.rs index eec51de..1a0d7c1 100644 --- a/src/text.rs +++ b/src/text.rs @@ -7,7 +7,7 @@ pub struct Text { lines: usize, // # of lines longest: usize, // longest line size: (usize, usize), // cols, rows - wide: bool, // in wide mode? turns off margins + wide: bool, // in wide mode? turns off margins } impl View for Text { @@ -42,7 +42,7 @@ impl View for Text { Action::Redraw } Key::Down | Key::Ctrl('n') | Key::Char('j') => { - if self.lines > SCROLL_LINES && self.scroll < (self.lines - SCROLL_LINES) { + if self.scroll < self.padding() { self.scroll += 1; Action::Redraw } else { @@ -70,13 +70,11 @@ impl View for Text { } } Key::PageDown | Key::Char(' ') => { - let lines = self.lines - 1; - if lines > SCROLL_LINES { - if self.scroll < lines - SCROLL_LINES { - self.scroll += SCROLL_LINES; - if self.scroll >= lines { - self.scroll = lines; - } + let padding = self.padding(); + if self.scroll < padding { + self.scroll += SCROLL_LINES; + if self.scroll >= padding { + self.scroll = padding; } Action::Redraw } else { @@ -144,4 +142,14 @@ impl Text { wide: false, } } + + // how many rows to pad with blank lines at the end of the page + fn padding(&self) -> usize { + let padding = (self.size.1 as f64 * 0.75) as usize; + if self.lines > padding { + self.lines - padding + } else { + 0 + } + } }