on master help sign in
fix: Wrap around the top of the picker menu when scrolling
c7d6e44Blaž Hrastnik
helix-term/src/ui/picker.rs+6−8
@@ -270,17 +270,15 @@ impl<T> Picker<T> {
270 }
270 }
271
271
272 pub fn move_up(&mut self) {
272 pub fn move_up(&mut self) {
273+ let len = self.matches.len();
273− self.cursor = self.cursor.saturating_sub(1);
274+ let pos = ((self.cursor + len.saturating_sub(1)) % len) % len;
275+ self.cursor = pos;
274 }
276 }
275
277
276 pub fn move_down(&mut self) {
278 pub fn move_down(&mut self) {
277− if self.matches.is_empty() {
279+ let len = self.matches.len();
278− return;
280+ let pos = (self.cursor + 1) % len;
279− }
280−
281− if self.cursor < self.matches.len() - 1 {
282− self.cursor += 1;
281+ self.cursor = pos;
283− }
284 }
282 }
285
283
286 pub fn selection(&self) -> Option<&T> {
284 pub fn selection(&self) -> Option<&T> {