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

feat(ui): remove whitespace in empty lines #1597

Merged
merged 3 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 10 additions & 9 deletions lua/mason-core/ui/display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,16 @@ local function render_node(viewport_context, node, _render_context, _output)
end
end

local active_styles = get_styles(full_line, render_context)

-- apply indentation
full_line = (" "):rep(active_styles.indentation) .. full_line
for j = 1, #line_highlights do
local highlight = line_highlights[j]
highlight.col_start = highlight.col_start + active_styles.indentation
highlight.col_end = highlight.col_end + active_styles.indentation
output.highlights[#output.highlights + 1] = highlight
-- only apply cascading styles to non-empty lines
if string.len(full_line) > 0 then
local active_styles = get_styles(full_line, render_context)
full_line = (" "):rep(active_styles.indentation) .. full_line
for j = 1, #line_highlights do
local highlight = line_highlights[j]
highlight.col_start = highlight.col_start + active_styles.indentation
highlight.col_end = highlight.col_end + active_styles.indentation
output.highlights[#output.highlights + 1] = highlight
end
end

output.lines[#output.lines + 1] = full_line
Expand Down
20 changes: 20 additions & 0 deletions tests/mason-core/ui_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,24 @@ describe("integration test", function()
)
end)
)

it("should not apply cascading styles to empty lines", function ()
local render_output = display._render_node(
{
win_width = 120,
},
Ui.CascadingStyleNode({ "INDENT" }, {
Ui.HlTextNode {
{
{ "Hello World!", "MyHighlightGroup" },
},
{
{ "", "" },
},
},
})
)

assert.same({" Hello World!", "" }, render_output.lines)
end)
end)
Loading