aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui/menu.rs
diff options
context:
space:
mode:
authorNathan Vegdahl2021-07-24 00:23:16 +0000
committerNathan Vegdahl2021-07-24 00:23:16 +0000
commit43594049ddd6b0ec3794807016ab3cd2a6a38834 (patch)
tree56e0bd5b7ac016937612aa650de2f06041a2e258 /helix-term/src/ui/menu.rs
parent427ae6ac6cfdd2a89580692dadd45f1a8dc02d2c (diff)
parentbda4f5c1cdd2f84a06647f7dce45a8f6d06401ae (diff)
Merge branch 'master' into great_line_ending_and_cursor_range_cleanup
Diffstat (limited to 'helix-term/src/ui/menu.rs')
-rw-r--r--helix-term/src/ui/menu.rs16
1 files changed, 7 insertions, 9 deletions
diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs
index 8681e5b1..5a6f6256 100644
--- a/helix-term/src/ui/menu.rs
+++ b/helix-term/src/ui/menu.rs
@@ -90,13 +90,13 @@ 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.options.len();
+ let pos = self.cursor.map_or(0, |i| i.saturating_sub(1)) % self.matches.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.options.len();
+ let pos = self.cursor.map_or(0, |i| i + 1) % self.matches.len();
self.cursor = Some(pos);
self.adjust_scroll();
}
@@ -233,16 +233,16 @@ impl<T: Item + 'static> Component for Menu<T> {
let max_lens = self.options.iter().fold(vec![0; n], |mut acc, option| {
let row = option.row();
// maintain max for each column
- for (i, cell) in row.cells.iter().enumerate() {
+ for (acc, cell) in acc.iter_mut().zip(row.cells.iter()) {
let width = cell.content.width();
- if width > acc[i] {
- acc[i] = width;
+ if width > *acc {
+ *acc = width;
}
}
acc
});
- let len = (max_lens.iter().sum::<usize>()) + n + 1; // +1: reserve some space for scrollbar
+ let len = max_lens.iter().sum::<usize>() + n + 1; // +1: reserve some space for scrollbar
let width = len.min(viewport.0 as usize);
self.widths = max_lens
@@ -250,9 +250,7 @@ impl<T: Item + 'static> Component for Menu<T> {
.map(|len| Constraint::Length(len as u16))
.collect();
- const MAX: usize = 10;
- let height = std::cmp::min(self.options.len(), MAX);
- let height = std::cmp::min(height, viewport.1 as usize);
+ let height = self.options.len().min(10).min(viewport.1 as usize);
self.size = (width as u16, height as u16);