From 9cd35f4f469c377c3f3774cbb4586d60acb835ce Mon Sep 17 00:00:00 2001 From: WillLillis Date: Wed, 10 Jan 2024 19:00:22 -0600 Subject: [PATCH 1/3] feat(ui): remove whitespace in empty lines --- lua/mason-core/ui/display.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lua/mason-core/ui/display.lua b/lua/mason-core/ui/display.lua index 4c6a06c29..e80f66e8e 100644 --- a/lua/mason-core/ui/display.lua +++ b/lua/mason-core/ui/display.lua @@ -121,13 +121,15 @@ local function render_node(viewport_context, node, _render_context, _output) 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 + -- apply indentation to non-empty lines + if string.len(full_line) > 0 then + 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 From a7eb53541d116e4d576657e1fb031ad35491527e Mon Sep 17 00:00:00 2001 From: William Boman Date: Sun, 21 Jan 2024 18:22:40 +0100 Subject: [PATCH 2/3] add test and move style computation inside conditional block --- lua/mason-core/ui/display.lua | 5 ++--- tests/mason-core/ui_spec.lua | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lua/mason-core/ui/display.lua b/lua/mason-core/ui/display.lua index e80f66e8e..c4aebd95d 100644 --- a/lua/mason-core/ui/display.lua +++ b/lua/mason-core/ui/display.lua @@ -119,10 +119,9 @@ local function render_node(viewport_context, node, _render_context, _output) end end - local active_styles = get_styles(full_line, render_context) - - -- apply indentation to non-empty lines + -- 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] diff --git a/tests/mason-core/ui_spec.lua b/tests/mason-core/ui_spec.lua index 40a8b8885..f2d7d5b54 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) From d46078e07248af4220f53c65392ef628edbff8b6 Mon Sep 17 00:00:00 2001 From: William Boman Date: Sun, 21 Jan 2024 18:25:28 +0100 Subject: [PATCH 3/3] stylua --- tests/mason-core/ui_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/mason-core/ui_spec.lua b/tests/mason-core/ui_spec.lua index f2d7d5b54..17087045e 100644 --- a/tests/mason-core/ui_spec.lua +++ b/tests/mason-core/ui_spec.lua @@ -324,7 +324,7 @@ describe("integration test", function() end) ) - it("should not apply cascading styles to empty lines", function () + it("should not apply cascading styles to empty lines", function() local render_output = display._render_node( { win_width = 120, @@ -341,6 +341,6 @@ describe("integration test", function() }) ) - assert.same({" Hello World!", "" }, render_output.lines) + assert.same({ " Hello World!", "" }, render_output.lines) end) end)