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.
commit1ac576f2b3ab3b3b1c398c57e1269682e6f63f3e
authorRohan Jain <343499+crodjer@users.noreply.github.com>
dateMon 14 Mar 2022, 08:16 (5 years ago)
parent29d6a5a
helix-term/src/ui/picker.rs+5
@@ -415,6 +415,11 @@ impl<T> Picker<T> {
415415 pub fn move_by(&mut self, amount: usize, direction: Direction) {
416416 let len = self.matches.len();
417417
418+ if len == 0 {
419+ // No results, can't move.
420+ return;
421+ }
422+
418423 match direction {
419424 Direction::Forward => {
420425 self.cursor = self.cursor.saturating_add(amount) % len;