on master help sign in
ui: menu: Don't allocate scrollbar space if options fit
commit36b975c4ce2502391873a086b10b46941d295ee4 authorBlaž Hrastnik <blaz@mxxn.io> dateTue 1 Feb 2022, 01:25 (5 years ago) parentf10a06f
1 file changed+11−3
helix-term/src/ui/menu.rs+11−3
helix-term/src/ui/menu.rs+11−3
@@ -139,7 +139,17 @@ impl<T: Item> Menu<T> {
139139
140140 acc
141141 });
142− let len = max_lens.iter().sum::<usize>() + n + 1; // +1: reserve some space for scrollbar
142+
143+ let height = self.matches.len().min(10).min(viewport.1 as usize);
144+ // do all the matches fit on a single screen?
145+ let fits = self.matches.len() <= height;
146+
147+ let mut len = max_lens.iter().sum::<usize>() + n;
148+
149+ if !fits {
150+ len += 1; // +1: reserve some space for scrollbar
151+ }
152+
143153 let width = len.min(viewport.0 as usize);
144154
145155 self.widths = max_lens
@@ -147,8 +157,6 @@ impl<T: Item> Menu<T> {
147157 .map(|len| Constraint::Length(len as u16))
148158 .collect();
149159
150− let height = self.matches.len().min(10).min(viewport.1 as usize);
151−
152160 self.size = (width as u16, height as u16);
153161
154162 // adjust scroll offsets if size changed