From 31cf6c5b1aeae04f597e2f1e8a9664dac218db3e Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Thu, 9 Jun 2022 23:00:29 +0530 Subject: [PATCH 1/2] Add single width left margin for completion popup --- helix-term/src/ui/menu.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index d67a429e37f3..bae2f49d5829 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -48,6 +48,8 @@ pub struct Menu { } impl Menu { + const LEFT_PADDING: usize = 1; + // TODO: it's like a slimmed down picker, share code? (picker = menu + prompt with different // rendering) pub fn new( @@ -150,6 +152,7 @@ impl Menu { len += 1; // +1: reserve some space for scrollbar } + len += Self::LEFT_PADDING; let width = len.min(viewport.0 as usize); self.widths = max_lens @@ -306,7 +309,7 @@ impl Component for Menu { use tui::widgets::TableState; table.render_table( - area, + area.clip_left(Self::LEFT_PADDING as u16), surface, &mut TableState { offset: scroll, @@ -314,6 +317,12 @@ impl Component for Menu { }, ); + 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() { From 23bc196dae703305aa07489b6583661b29021ca0 Mon Sep 17 00:00:00 2001 From: Gokul Soumya Date: Tue, 21 Jun 2022 23:20:57 +0530 Subject: [PATCH 2/2] Clear with ui.menu style before rendering menu When rendering a completion popup, the popup component will clear the area with ui.popup and then the menu component would draw over it using a table component. We remove the left edge of the area before passing it to the table component (so that it will be left as padding), and the table component uses ui.menu as the style. If ui.menu and ui.popup are different the left edge of the popup will look different from the rest of the popup. We avoid this by clearing the whole area with ui.menu in Menu::render --- helix-term/src/ui/menu.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index bae2f49d5829..8c203c6a647e 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -274,6 +274,7 @@ impl Component for Menu { .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;