on master help sign in
ui: menu: Allow wrapping around on ctrl-p/shift tab
b20a5c4Blaž Hrastnik
helix-term/src/ui/menu.rs+4−3
@@ -89,14 +89,15 @@ impl<T: Item> Menu<T> {
89 }
89 }
90
90
91 pub fn move_up(&mut self) {
91 pub fn move_up(&mut self) {
92− // TODO: wrap around to end
92+ let len = self.matches.len();
93− let pos = self.cursor.map_or(0, |i| i.saturating_sub(1)) % self.matches.len();
93+ let pos = self.cursor.map_or(0, |i| (i + len.saturating_sub(1)) % len) % len;
94 self.cursor = Some(pos);
94 self.cursor = Some(pos);
95 self.adjust_scroll();
95 self.adjust_scroll();
96 }
96 }
97
97
98 pub fn move_down(&mut self) {
98 pub fn move_down(&mut self) {
99+ let len = self.matches.len();
99− let pos = self.cursor.map_or(0, |i| i + 1) % self.matches.len();
100+ let pos = self.cursor.map_or(0, |i| i + 1) % len;
100 self.cursor = Some(pos);
101 self.cursor = Some(pos);
101 self.adjust_scroll();
102 self.adjust_scroll();
102 }
103 }