fix some overflows

pull/6/head
dvkt 5 years ago
parent b72daf2946
commit 0021035908

@ -24,6 +24,8 @@ pub struct Line {
link: usize, // link #, if any
}
const SCROLL_LINES: usize = 15;
impl View for MenuView {
fn render(&self, cols: usize, rows: usize) -> String {
self.render_lines(cols, rows)
@ -128,8 +130,9 @@ impl MenuView {
}
fn action_page_down(&mut self) -> Action {
if self.scroll < self.lines().len() - 15 {
self.scroll += 15;
let lines = self.lines().len();
if lines > SCROLL_LINES && self.scroll < lines - SCROLL_LINES {
self.scroll += SCROLL_LINES;
Action::Redraw
} else {
Action::None
@ -138,8 +141,9 @@ impl MenuView {
fn action_page_up(&mut self) -> Action {
if self.scroll > 0 {
self.scroll -= 15;
if self.scroll < 0 {
if self.scroll > SCROLL_LINES {
self.scroll -= SCROLL_LINES;
} else {
self.scroll = 0;
}
Action::Redraw

@ -22,8 +22,12 @@ impl View for TextView {
Action::Redraw
}
Key::Char('b') | Key::Char('G') => {
self.scroll = self.lines - SCROLL_LINES;
Action::Redraw
if self.lines >= SCROLL_LINES {
self.scroll = self.lines - SCROLL_LINES;
Action::Redraw
} else {
Action::None
}
}
Key::Down => {
if self.scroll < self.lines - 1 {
@ -43,8 +47,9 @@ impl View for TextView {
}
Key::PageUp | Key::Char('-') => {
if self.scroll > 0 {
self.scroll -= SCROLL_LINES;
if self.scroll < 0 {
if self.scroll >= SCROLL_LINES {
self.scroll -= SCROLL_LINES;
} else {
self.scroll = 0;
}
Action::Redraw
@ -53,10 +58,13 @@ impl View for TextView {
}
}
Key::PageDown | Key::Char(' ') => {
if self.scroll < self.lines - 1 - SCROLL_LINES {
self.scroll += SCROLL_LINES;
if self.scroll >= self.lines {
self.scroll = self.lines - 1;
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;
}
}
Action::Redraw
} else {

Loading…
Cancel
Save