Picker: Don't panick at move_up/move_down when matches is empty (#818)

imgbot
Leoi Hung Kin 3 years ago committed by GitHub
parent eedcea7e6b
commit a6852fb88f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

Loading…
Cancel
Save