Picker: Don't panick at move_up/move_down when matches is empty (#818)
This commit is contained in:
parent
eedcea7e6b
commit
a6852fb88f
1 changed files with 6 additions and 0 deletions
|
@ -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…
Add table
Reference in a new issue