Skip to content

Commit

Permalink
ui: menu: Allow wrapping around on ctrl-p/shift tab
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Aug 6, 2021
1 parent 66a9013 commit b20a5c4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions helix-term/src/ui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ impl<T: Item> Menu<T> {
}

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();
}
Expand Down

0 comments on commit b20a5c4

Please # to comment.