Skip to content

Commit

Permalink
separate newline style from whitespace style
Browse files Browse the repository at this point in the history
New "ui.virtual.newline" style is used for newline characters.
Will fallback on "ui.virtual.whitespace" if not defined.

Useful when newline render is 'after-whitespace', since in this case
you want it to stand out, whereas other whitespace characters would
need to blend in the background.

It was also conflicting with my theme where string literals are
underlined, and the "ui.virtual.whitespace" fg color was applied
on the underline on whitespaces inside strings.

Example theme:
    "ui.virtual.whitespace" = { fg = "gray", modifiers = ["dim"] }
    "ui.virtual.newline" = { fg = "red", modifiers = ["bold"] }
  • Loading branch information
jean-dao committed Apr 20, 2024
1 parent 3d0e232 commit b026823
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion helix-term/src/ui/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ pub struct TextRenderer<'a> {
pub surface: &'a mut Surface,
pub text_style: Style,
pub whitespace_style: Style,
pub newline_style: Style,
pub indent_guide_char: String,
pub indent_guide_style: Style,
pub newline: NewlineRendering,
Expand Down Expand Up @@ -451,6 +452,9 @@ impl<'a> TextRenderer<'a> {
tab,
virtual_tab,
whitespace_style: theme.get("ui.virtual.whitespace"),
newline_style: theme
.try_get("ui.virtual.newline")
.unwrap_or_else(|| theme.get("ui.virtual.whitespace")),
indent_width,
starting_indent: col_offset / indent_width as usize
+ (col_offset % indent_width as usize != 0) as usize
Expand Down Expand Up @@ -484,7 +488,11 @@ impl<'a> TextRenderer<'a> {
// TODO is it correct to apply the whitespace style to all unicode white spaces?
let mut style = grapheme_style.syntax_style;
if is_whitespace {
style = style.patch(self.whitespace_style);
style = if grapheme == Grapheme::Newline {
style.patch(self.newline_style)
} else {
style.patch(self.whitespace_style)
};
}
style = style.patch(grapheme_style.overlay_style);

Expand Down

0 comments on commit b026823

Please sign in to comment.