From b20a5c4c0ef16bb0298d072ac7ac8450796b5954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Fri, 6 Aug 2021 11:22:23 +0900 Subject: [PATCH] ui: menu: Allow wrapping around on ctrl-p/shift tab --- helix-term/src/ui/menu.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index 5a6f6256a..1e1c54272 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -89,14 +89,15 @@ impl Menu { } pub fn move_up(&mut self) { - // TODO: wrap around to end - let pos = self.cursor.map_or(0, |i| i.saturating_sub(1)) % self.matches.len(); + let len = self.matches.len(); + let pos = self.cursor.map_or(0, |i| (i + len.saturating_sub(1)) % len) % len; self.cursor = Some(pos); self.adjust_scroll(); } pub fn move_down(&mut self) { - let pos = self.cursor.map_or(0, |i| i + 1) % self.matches.len(); + let len = self.matches.len(); + let pos = self.cursor.map_or(0, |i| i + 1) % len; self.cursor = Some(pos); self.adjust_scroll(); }