fix: Wrap around the top of the picker menu when scrolling

Forgot to port the improvements in menu.rs

Fixes #734
imgbot
Blaž Hrastnik 3 years ago
parent b02d872938
commit c7d6e4461f

@ -270,17 +270,15 @@ impl<T> Picker<T> {
} }
pub fn move_up(&mut self) { pub fn move_up(&mut self) {
self.cursor = self.cursor.saturating_sub(1); let len = self.matches.len();
let pos = ((self.cursor + len.saturating_sub(1)) % len) % len;
self.cursor = pos;
} }
pub fn move_down(&mut self) { pub fn move_down(&mut self) {
if self.matches.is_empty() { let len = self.matches.len();
return; let pos = (self.cursor + 1) % len;
} self.cursor = pos;
if self.cursor < self.matches.len() - 1 {
self.cursor += 1;
}
} }
pub fn selection(&self) -> Option<&T> { pub fn selection(&self) -> Option<&T> {

Loading…
Cancel
Save