Handle panic on move within empty picker (#1786)

When the picker results output is empty, movement actions result in a panic:
```
thread 'main' panicked at 'attempt to calculate the remainder with a divisor of zero', helix-term/src/ui/picker.rs:420:31
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

This could be a no-op instead when the matches length is zero.
This commit is contained in:
Rohan Jain 2022-03-14 08:16:23 +05:30 committed by GitHub
parent 29d6a5a9b6
commit 1ac576f2b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -415,6 +415,11 @@ impl<T> Picker<T> {
pub fn move_by(&mut self, amount: usize, direction: Direction) {
let len = self.matches.len();
if len == 0 {
// No results, can't move.
return;
}
match direction {
Direction::Forward => {
self.cursor = self.cursor.saturating_add(amount) % len;