on master help sign in
Picker: Don't panick at move_up/move_down when matches is empty (#818)
commita6852fb88f72ea6bb41b19e65b531c17662ba57d authorLeoi Hung Kin <leoihungkin@outlook.com> dateSat 9 Oct 2021, 19:34 (5 years ago) parenteedcea7
1 file changed+6
helix-term/src/ui/picker.rs+6
helix-term/src/ui/picker.rs+6
@@ -270,12 +270,18 @@ impl<T> Picker<T> {
270270 }
271271
272272 pub fn move_up(&mut self) {
273+ if self.matches.is_empty() {
274+ return;
275+ }
273276 let len = self.matches.len();
274277 let pos = ((self.cursor + len.saturating_sub(1)) % len) % len;
275278 self.cursor = pos;
276279 }
277280
278281 pub fn move_down(&mut self) {
282+ if self.matches.is_empty() {
283+ return;
284+ }
279285 let len = self.matches.len();
280286 let pos = (self.cursor + 1) % len;
281287 self.cursor = pos;