Skip to content

Commit

Permalink
Add ability to theme primary selecition
Browse files Browse the repository at this point in the history
  • Loading branch information
vv9k authored and archseer committed Jun 23, 2021
1 parent ac1e98d commit d70be55
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions book/src/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Possible keys:
| `ui.text.focus` | |
| `ui.menu.selected` | |
| `ui.selection` | For selections in the editing area |
| `ui.selection.primary` | |
| `warning` | LSP warning |
| `error` | LSP error |
| `info` | LSP info |
Expand Down
25 changes: 18 additions & 7 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,27 @@ impl EditorView {
});

let selection_style = theme.get("ui.selection");
let primary_style = theme
.try_get("ui.selection.primary")
.unwrap_or(selection_style);
let selection = doc.selection(view.id);
let primary_idx = selection.primary_index();

for selection in doc
.selection(view.id)
for (i, selection) in selection
.iter()
.filter(|range| range.overlaps(&screen))
.enumerate()
.filter(|(_, range)| range.overlaps(&screen))
{
// TODO: render also if only one of the ranges is in viewport
let mut start = view.screen_coords_at_pos(doc, text, selection.anchor);
let mut end = view.screen_coords_at_pos(doc, text, selection.head);

let style = if i != primary_idx {
selection_style
} else {
primary_style
};

let head = end;

if selection.head < selection.anchor {
Expand Down Expand Up @@ -331,7 +342,7 @@ impl EditorView {
),
1,
),
selection_style,
style,
);
} else {
surface.set_style(
Expand All @@ -342,7 +353,7 @@ impl EditorView {
viewport.width.saturating_sub(start.col as u16),
1,
),
selection_style,
style,
);
for i in start.row + 1..end.row {
surface.set_style(
Expand All @@ -353,7 +364,7 @@ impl EditorView {
viewport.width,
1,
),
selection_style,
style,
);
}
surface.set_style(
Expand All @@ -363,7 +374,7 @@ impl EditorView {
(end.col as u16).min(viewport.width),
1,
),
selection_style,
style,
);
}

Expand Down
3 changes: 2 additions & 1 deletion theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"ui.text" = { fg = "#a4a0e8" } # lavender
"ui.text.focus" = { fg = "#dbbfef"} # lilac

"ui.selection" = { bg = "#540099" }
"ui.selection" = { bg = "#44258b" }
"ui.selection.primary" = { bg = "#540099" }
"ui.menu.selected" = { fg = "#281733", bg = "#ffffff" } # revolver

"warning" = "#ffcd1c"
Expand Down

0 comments on commit d70be55

Please sign in to comment.