on master help sign in
ui: menu: Don't allocate scrollbar space if options fit
36b975cBlaž Hrastnik
helix-term/src/ui/menu.rs+11−3
@@ -139,7 +139,17 @@ impl<T: Item> Menu<T> {
139
139
140 acc
140 acc
141 });
141 });
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 {
142− let len = max_lens.iter().sum::<usize>() + n + 1; // +1: reserve some space for scrollbar
150+ len += 1; // +1: reserve some space for scrollbar
151+ }
152+
143 let width = len.min(viewport.0 as usize);
153 let width = len.min(viewport.0 as usize);
144
154
145 self.widths = max_lens
155 self.widths = max_lens
@@ -147,8 +157,6 @@ impl<T: Item> Menu<T> {
147 .map(|len| Constraint::Length(len as u16))
157 .map(|len| Constraint::Length(len as u16))
148 .collect();
158 .collect();
149
159
150− let height = self.matches.len().min(10).min(viewport.1 as usize);
151−
152 self.size = (width as u16, height as u16);
160 self.size = (width as u16, height as u16);
153
161
154 // adjust scroll offsets if size changed
162 // adjust scroll offsets if size changed