on master help sign in
Right align scrollbar with track in completion popup (#2754)

- Align the scollbar to the right edge of the popup rather than at a margin of one. - Add a scrollbar track and a new scope `ui.menu.scroll`.

commita26943de4e421a453371aa53b3bb11a2baabff56 authorGokul Soumya <gokulps15@gmail.com> dateMon 27 Jun 2022, 13:22 (4 years ago) parentc113531
4 files changed+22−7
book/src/themes.md+1 helix-term/src/ui/menu.rs+19−7 runtime/themes/onedark.toml+1 theme.toml+1
book/src/themes.md+1
@@ -231,6 +231,7 @@ These scopes are used for theming the editor interface.
231231| `ui.virtual.indent-guide` | Vertical indent width guides |
232232| `ui.menu` | Code and command completion menus |
233233| `ui.menu.selected` | Selected autocomplete item |
234+| `ui.menu.scroll` | `fg` sets thumb color, `bg` sets track color of scrollbar |
234235| `ui.selection` | For selections in the editing area |
235236| `ui.selection.primary` | |
236237| `warning` | Diagnostics warning (gutter) |
helix-term/src/ui/menu.rs+19−7
@@ -310,7 +310,7 @@ impl<T: Item + 'static> Component for Menu<T> {
310310 use tui::widgets::TableState;
311311
312312 table.render_table(
313− area.clip_left(Self::LEFT_PADDING as u16),
313+ area.clip_left(Self::LEFT_PADDING as u16).clip_right(1),
314314 surface,
315315 &mut TableState {
316316 offset: scroll,
@@ -320,20 +320,32 @@ impl<T: Item + 'static> Component for Menu<T> {
320320
321321 if let Some(cursor) = self.cursor {
322322 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);
323+ let left = &mut surface[(area.left(), area.y + offset_from_top as u16)];
324+ left.set_style(selected);
325+ let right = &mut surface[(
326+ area.right().saturating_sub(1),
327+ area.y + offset_from_top as u16,
328+ )];
329+ right.set_style(selected);
325330 }
326331
327332 let fits = len <= win_height;
328333
334+ let scroll_style = theme.get("ui.menu.scroll");
329335 for (i, _) in (scroll..(scroll + win_height).min(len)).enumerate() {
336+ let cell = &mut surface[(area.x + area.width - 1, area.y + i as u16)];
337+
338+ if !fits {
339+ // Draw scroll track
340+ cell.set_symbol("▐"); // right half block
341+ cell.set_fg(scroll_style.bg.unwrap_or(helix_view::theme::Color::Reset));
342+ }
343+
330344 let is_marked = i >= scroll_line && i < scroll_line + scroll_height;
331345
332346 if !fits && is_marked {
333− let cell = &mut surface[(area.x + area.width - 2, area.y + i as u16)];
334− cell.set_symbol("▐");
335− // cell.set_style(selected);
336− // cell.set_style(if is_marked { selected } else { style });
347+ // Draw scroll thumb
348+ cell.set_fg(scroll_style.fg.unwrap_or(helix_view::theme::Color::Reset));
337349 }
338350 }
339351 }
runtime/themes/onedark.toml+1
@@ -73,6 +73,7 @@ diagnostic = { modifiers = ["underlined"] }
7373"ui.window" = { bg = "gray" }
7474"ui.menu" = { fg = "white", bg = "gray" }
7575"ui.menu.selected" = { fg = "black", bg = "blue" }
76+"ui.menu.scroll" = { fg = "white", bg = "light-gray" }
7677
7778[palette]
7879
theme.toml+1
@@ -69,6 +69,7 @@ label = "honey"
6969
7070"ui.menu" = { fg = "lavender", bg = "revolver" }
7171"ui.menu.selected" = { fg = "revolver", bg = "white" }
72+"ui.menu.scroll" = { fg = "lavender", bg = "comet" }
7273
7374diagnostic = { modifiers = ["underlined"] }
7475# "diagnostic.hint" = { fg = "revolver", bg = "lilac" }