Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add single width left margin for completion popup #2728

Merged
merged 2 commits into from
Jun 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion helix-term/src/ui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub struct Menu<T: Item> {
}

impl<T: Item> Menu<T> {
const LEFT_PADDING: usize = 1;

// TODO: it's like a slimmed down picker, share code? (picker = menu + prompt with different
// rendering)
pub fn new(
Expand Down Expand Up @@ -150,6 +152,7 @@ impl<T: Item> Menu<T> {
len += 1; // +1: reserve some space for scrollbar
}

len += Self::LEFT_PADDING;
let width = len.min(viewport.0 as usize);

self.widths = max_lens
Expand Down Expand Up @@ -271,6 +274,7 @@ impl<T: Item + 'static> Component for Menu<T> {
.try_get("ui.menu")
.unwrap_or_else(|| theme.get("ui.text"));
let selected = theme.get("ui.menu.selected");
surface.clear_with(area, style);

let scroll = self.scroll;

Expand Down Expand Up @@ -306,14 +310,20 @@ impl<T: Item + 'static> Component for Menu<T> {
use tui::widgets::TableState;

table.render_table(
area,
area.clip_left(Self::LEFT_PADDING as u16),
surface,
&mut TableState {
offset: scroll,
selected: self.cursor,
},
);

if let Some(cursor) = self.cursor {
let offset_from_top = cursor - scroll;
let cell = &mut surface[(area.x, area.y + offset_from_top as u16)];
cell.set_style(selected);
}

let fits = len <= win_height;

for (i, _) in (scroll..(scroll + win_height).min(len)).enumerate() {
Expand Down