Skip to content

Commit 16ccc7e

Browse files
authored
Add single width left margin for completion popup (#2728)
* Add single width left margin for completion popup * 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
1 parent ba85779 commit 16ccc7e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

helix-term/src/ui/menu.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub struct Menu<T: Item> {
4848
}
4949

5050
impl<T: Item> Menu<T> {
51+
const LEFT_PADDING: usize = 1;
52+
5153
// TODO: it's like a slimmed down picker, share code? (picker = menu + prompt with different
5254
// rendering)
5355
pub fn new(
@@ -150,6 +152,7 @@ impl<T: Item> Menu<T> {
150152
len += 1; // +1: reserve some space for scrollbar
151153
}
152154

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

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

275279
let scroll = self.scroll;
276280

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

308312
table.render_table(
309-
area,
313+
area.clip_left(Self::LEFT_PADDING as u16),
310314
surface,
311315
&mut TableState {
312316
offset: scroll,
313317
selected: self.cursor,
314318
},
315319
);
316320

321+
if let Some(cursor) = self.cursor {
322+
let offset_from_top = cursor - scroll;
323+
let cell = &mut surface[(area.x, area.y + offset_from_top as u16)];
324+
cell.set_style(selected);
325+
}
326+
317327
let fits = len <= win_height;
318328

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

0 commit comments

Comments
 (0)