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

This commit is contained in:
Leoi Hung Kin 2021-10-09 19:34:10 +08:00 committed by GitHub
parent eedcea7e6b
commit a6852fb88f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;