From 45d15bf03a54e4c54ee49b68f4483dcbf0664704 Mon Sep 17 00:00:00 2001 From: Ferran Basora Date: Tue, 12 Mar 2019 22:27:21 +0000 Subject: [PATCH] Fix bug in selection navigation --- src/view.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/view.rs b/src/view.rs index 151afe6..e6c8d0b 100644 --- a/src/view.rs +++ b/src/view.rs @@ -39,8 +39,10 @@ impl<'a> View<'a> { } } - pub fn next(&mut self) { - self.skip = self.skip + 1; + pub fn next(&mut self, maximum: usize) { + if self.skip < maximum { + self.skip = self.skip + 1; + } } pub fn present(&mut self) -> Option<(String, bool)> { @@ -114,9 +116,9 @@ impl<'a> View<'a> { } } Key::Up => { self.prev(); } - Key::Down => { self.next(); } + Key::Down => { self.next(matches.len() - 1); } Key::Left => { self.prev(); } - Key::Right => { self.next(); } + Key::Right => { self.next(matches.len() - 1); } Key::Char(ch) => { let key = ch.to_string(); let lower_key = key.to_lowercase();