Skip to content

Commit

Permalink
fix(ui): don't indent empty lines (#1597)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillLillis committed Jan 21, 2024
1 parent e110bc3 commit c7e6705
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
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)

0 comments on commit c7e6705

Please sign in to comment.