on master help sign in
fix: Wrap around the top of the picker menu when scrolling

Forgot to port the improvements in menu.rs Fixes #734

commitc7d6e4461f249108189cddf44b487b4c71c5520a authorBlaž Hrastnik <blaz@mxxn.io> dateFri 17 Sep 2021, 14:34 (5 years ago) parentb02d872
1 file changed+6−8
helix-term/src/ui/picker.rs+6−8
helix-term/src/ui/picker.rs+6−8
@@ -270,17 +270,15 @@ impl<T> Picker<T> {
270270 }
271271
272272 pub fn move_up(&mut self) {
273− self.cursor = self.cursor.saturating_sub(1);
273+ let len = self.matches.len();
274+ let pos = ((self.cursor + len.saturating_sub(1)) % len) % len;
275+ self.cursor = pos;
274276 }
275277
276278 pub fn move_down(&mut self) {
277− if self.matches.is_empty() {
278− return;
279− }
280−
281− if self.cursor < self.matches.len() - 1 {
282− self.cursor += 1;
283− }
279+ let len = self.matches.len();
280+ let pos = (self.cursor + 1) % len;
281+ self.cursor = pos;
284282 }
285283
286284 pub fn selection(&self) -> Option<&T> {