on master help sign in
Picker: Don't panick at move_up/move_down when matches is empty (#818)
a6852fbLeoi Hung Kin
helix-term/src/ui/picker.rs+6
@@ -270,12 +270,18 @@ impl<T> Picker<T> {
270 }
270 }
271
271
272 pub fn move_up(&mut self) {
272 pub fn move_up(&mut self) {
273+ if self.matches.is_empty() {
274+ return;
275+ }
273 let len = self.matches.len();
276 let len = self.matches.len();
274 let pos = ((self.cursor + len.saturating_sub(1)) % len) % len;
277 let pos = ((self.cursor + len.saturating_sub(1)) % len) % len;
275 self.cursor = pos;
278 self.cursor = pos;
276 }
279 }
277
280
278 pub fn move_down(&mut self) {
281 pub fn move_down(&mut self) {
282+ if self.matches.is_empty() {
283+ return;
284+ }
279 let len = self.matches.len();
285 let len = self.matches.len();
280 let pos = (self.cursor + 1) % len;
286 let pos = (self.cursor + 1) % len;
281 self.cursor = pos;
287 self.cursor = pos;