From 82a95dfd8919aac8a37a47846cb568f42c5c2814 Mon Sep 17 00:00:00 2001 From: Rohan Jain Date: Fri, 11 Mar 2022 12:01:28 +0530 Subject: [PATCH] Handle panic on move within empty picker 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. --- helix-term/src/ui/picker.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index 5d88622c9cb7..3f2da92fae69 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -415,6 +415,11 @@ impl Picker { 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;