Skip to content

Commit

Permalink
Handle panic on move within empty picker (#1786)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crodjer authored Mar 14, 2022
1 parent 29d6a5a commit 1ac576f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1ac576f

Please sign in to comment.