on master help sign in
ui: menu: Allow wrapping around on ctrl-p/shift tab
commitb20a5c4c0ef16bb0298d072ac7ac8450796b5954 authorBlaž Hrastnik <blaz@mxxn.io> dateFri 6 Aug 2021, 11:22 (5 years ago) parent66a9013
1 file changed+4−3
helix-term/src/ui/menu.rs+4−3
helix-term/src/ui/menu.rs+4−3
@@ -89,14 +89,15 @@ impl<T: Item> Menu<T> {
8989 }
9090
9191 pub fn move_up(&mut self) {
92− // TODO: wrap around to end
93− let pos = self.cursor.map_or(0, |i| i.saturating_sub(1)) % self.matches.len();
92+ let len = self.matches.len();
93+ let pos = self.cursor.map_or(0, |i| (i + len.saturating_sub(1)) % len) % len;
9494 self.cursor = Some(pos);
9595 self.adjust_scroll();
9696 }
9797
9898 pub fn move_down(&mut self) {
99− let pos = self.cursor.map_or(0, |i| i + 1) % self.matches.len();
99+ let len = self.matches.len();
100+ let pos = self.cursor.map_or(0, |i| i + 1) % len;
100101 self.cursor = Some(pos);
101102 self.adjust_scroll();
102103 }