Skip to content

Commit

Permalink
ui: menu: Don't allocate scrollbar space if options fit
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Jan 31, 2022
1 parent f10a06f commit 36b975c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions helix-term/src/ui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,24 @@ impl<T: Item> Menu<T> {

acc
});
let len = max_lens.iter().sum::<usize>() + n + 1; // +1: reserve some space for scrollbar

let height = self.matches.len().min(10).min(viewport.1 as usize);
// do all the matches fit on a single screen?
let fits = self.matches.len() <= height;

let mut len = max_lens.iter().sum::<usize>() + n;

if !fits {
len += 1; // +1: reserve some space for scrollbar
}

let width = len.min(viewport.0 as usize);

self.widths = max_lens
.into_iter()
.map(|len| Constraint::Length(len as u16))
.collect();

let height = self.matches.len().min(10).min(viewport.1 as usize);

self.size = (width as u16, height as u16);

// adjust scroll offsets if size changed
Expand Down

0 comments on commit 36b975c

Please sign in to comment.