From c7d6e4461f249108189cddf44b487b4c71c5520a Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Fri, 17 Sep 2021 14:34:59 +0900 Subject: fix: Wrap around the top of the picker menu when scrolling Forgot to port the improvements in menu.rs Fixes #734 --- helix-term/src/ui/picker.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'helix-term/src') diff --git a/helix-term/src/ui/picker.rs b/helix-term/src/ui/picker.rs index e040e0ff..c5b90a9c 100644 --- a/helix-term/src/ui/picker.rs +++ b/helix-term/src/ui/picker.rs @@ -270,17 +270,15 @@ impl Picker { } pub fn move_up(&mut self) { - self.cursor = self.cursor.saturating_sub(1); + 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; - } - - if self.cursor < self.matches.len() - 1 { - self.cursor += 1; - } + let len = self.matches.len(); + let pos = (self.cursor + 1) % len; + self.cursor = pos; } pub fn selection(&self) -> Option<&T> { -- cgit v1.2.3-70-g09d2