From a6852fb88f72ea6bb41b19e65b531c17662ba57d Mon Sep 17 00:00:00 2001 From: Leoi Hung Kin Date: Sat, 9 Oct 2021 19:34:10 +0800 Subject: [PATCH] Picker: Don't panick at move_up/move_down when matches is empty (#818) --- helix-term/src/ui/picker.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index c5b90a9ca..9be2a73e2 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -270,12 +270,18 @@ impl Picker { } 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;