Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix indent guide styling #3324

Merged
merged 5 commits into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,11 @@ impl EditorView {

let mut is_in_indent_area = true;
let mut last_line_indent_level = 0;
let indent_style = theme.get("ui.virtual.indent-guide");

// use whitespace style as fallback for indent-guide
let indent_guide_style = theme
.try_get("ui.virtual.indent-guide")
.unwrap_or_else(|| theme.get("ui.virtual.whitespace"));

let draw_indent_guides = |indent_level, line, surface: &mut Surface| {
if !config.indent_guides.render {
Expand All @@ -430,7 +434,7 @@ impl EditorView {
viewport.x + (i * tab_width as u16) - offset.col as u16,
viewport.y + line,
&indent_guide_char,
indent_style,
text_style.patch(indent_guide_style),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a good idea to patch ui.virtual.indent-guide if it exists? I think it should only patch ui.virtual.whitespace as a fallback rather than patching ui.virtual.indent-guide if it exists. I am still undecided since users may put ui.virtual.indent-guide without specifying a background.

Also, rather than doing this in a loop, I think it might be better if we patch it directly to indent_guide_style rather than doing this in the inner function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I'm patching it with text_style is that if users only specify the foreground, it should use the background from text_style. If you look at line 457, all styles are patched from text_style

let style = spans
    .iter()
    .fold(text_style, |acc, span| acc.patch(theme.highlight(span.0)));

You're right about doing it outside of the loop, will fix.

);
}
};
Expand Down Expand Up @@ -487,14 +491,7 @@ impl EditorView {
);
}

// This is an empty line; draw indent guides at previous line's
// indent level to avoid breaking the guides on blank lines.
if visual_x == 0 {
draw_indent_guides(last_line_indent_level, line, surface);
} else if is_in_indent_area {
// A line with whitespace only
draw_indent_guides(visual_x, line, surface);
}
draw_indent_guides(last_line_indent_level, line, surface);

visual_x = 0;
line += 1;
Expand Down
1 change: 0 additions & 1 deletion runtime/themes/dark_plus.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@

"ui.virtual.whitespace" = { fg = "dark_gray" }
"ui.virtual.ruler" = { bg = "borders" }
"ui.virtual.indent-guide" = { bg = "dark_gray4" }
A-Walrus marked this conversation as resolved.
Show resolved Hide resolved

"warning" = { fg = "gold2" }
"error" = { fg = "red" }
Expand Down