From c7e67059bb8ce7e126263471645c531d961b5e1d Mon Sep 17 00:00:00 2001 From: Will Lillis Date: Sun, 21 Jan 2024 12:26:29 -0500 Subject: [PATCH] fix(ui): don't indent empty lines (#1597) --- lua/mason-core/ui/display.lua | 19 ++++++++++--------- tests/mason-core/ui_spec.lua | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lua/mason-core/ui/display.lua b/lua/mason-core/ui/display.lua index 4c6a06c29..c4aebd95d 100644 --- a/lua/mason-core/ui/display.lua +++ b/lua/mason-core/ui/display.lua @@ -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 diff --git a/tests/mason-core/ui_spec.lua b/tests/mason-core/ui_spec.lua index 40a8b8885..17087045e 100644 --- a/tests/mason-core/ui_spec.lua +++ b/tests/mason-core/ui_spec.lua @@ -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)