@@ -90,13 +90,13 @@ impl<T: Item> Menu<T> {
91 pub fn move_up(&mut self) {
91 pub fn move_up(&mut self) {
92 // TODO: wrap around to end
92 // TODO: wrap around to end
93− let pos = self.cursor.map_or(0, |i| i.saturating_sub(1)) % self.options.len();
93+ let pos = self.cursor.map_or(0, |i| i.saturating_sub(1)) % self.matches.len();
94 self.cursor = Some(pos);
94 self.cursor = Some(pos);
95 self.adjust_scroll();
95 self.adjust_scroll();
98 pub fn move_down(&mut self) {
98 pub fn move_down(&mut self) {
99− let pos = self.cursor.map_or(0, |i| i + 1) % self.options.len();
99+ let pos = self.cursor.map_or(0, |i| i + 1) % self.matches.len();
100 self.cursor = Some(pos);
100 self.cursor = Some(pos);
101 self.adjust_scroll();
101 self.adjust_scroll();
@@ -233,16 +233,16 @@ impl<T: Item + 'static> Component for Menu<T> {
233 let max_lens = self.options.iter().fold(vec![0; n], |mut acc, option| {
233 let max_lens = self.options.iter().fold(vec![0; n], |mut acc, option| {
234 let row = option.row();
234 let row = option.row();
235 // maintain max for each column
235 // maintain max for each column
236− for (i, cell) in row.cells.iter().enumerate() {
236+ for (acc, cell) in acc.iter_mut().zip(row.cells.iter()) {
237 let width = cell.content.width();
237 let width = cell.content.width();
238− if width > acc[i] {
238+ if width > *acc {
239− acc[i] = width;
239+ *acc = width;
245− let len = (max_lens.iter().sum::<usize>()) + n + 1; // +1: reserve some space for scrollbar
245+ let len = max_lens.iter().sum::<usize>() + n + 1; // +1: reserve some space for scrollbar
246 let width = len.min(viewport.0 as usize);
246 let width = len.min(viewport.0 as usize);
248 self.widths = max_lens
248 self.widths = max_lens
@@ -250,9 +250,7 @@ impl<T: Item + 'static> Component for Menu<T> {
250 .map(|len| Constraint::Length(len as u16))
250 .map(|len| Constraint::Length(len as u16))
251 .collect();
251 .collect();
253− const MAX: usize = 10;
254− let height = std::cmp::min(self.options.len(), MAX);
253+ let height = self.options.len().min(10).min(viewport.1 as usize);
255− let height = std::cmp::min(height, viewport.1 as usize);
257 self.size = (width as u16, height as u16);
255 self.size = (width as u16, height as u16);