Skip to content

Commit 36b975c

Browse files
committed
ui: menu: Don't allocate scrollbar space if options fit
1 parent f10a06f commit 36b975c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

helix-term/src/ui/menu.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,24 @@ 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
146156
.into_iter()
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

0 commit comments

Comments
 (0)