From 73b16d35bb72b326e512eb85e6eea0830c8ec124 Mon Sep 17 00:00:00 2001 From: James Campos Date: Sun, 19 Apr 2020 07:42:58 -0700 Subject: bounds --- src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 877f9e3..c21f7c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -160,9 +160,11 @@ impl Bk { } } KeyCode::Char('n') => { - self.pos = 0; - self.chapter_idx += 1; - self.load_chapter(); + if self.chapter_idx < self.toc.len() - 1 { + self.pos = 0; + self.chapter_idx += 1; + self.load_chapter(); + } } KeyCode::Char('h') | KeyCode::Char('k') @@ -182,8 +184,9 @@ impl Bk { | KeyCode::Char('j') | KeyCode::Char('l') | KeyCode::Char(' ') => { - self.pos += self.rows; - if self.pos >= self.chapter.len() { + if self.pos + self.rows < self.chapter.len() { + self.pos += self.rows; + } else if self.chapter_idx < self.toc.len() - 1 { self.chapter_idx += 1; self.load_chapter(); self.pos = 0; -- cgit v1.2.3