aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWill Lillis <wlillis@umass.edu>2024-01-21 12:26:29 -0500
committerGitHub <noreply@github.com>2024-01-21 18:26:29 +0100
commitc7e67059bb8ce7e126263471645c531d961b5e1d (patch)
tree3b5e12b6dda6917df2df8a03b9fb5df0ac048db5
parenttests: add nvim v0.9.5 to test matrix (#1594) (diff)
downloadmason-c7e67059bb8ce7e126263471645c531d961b5e1d.tar
mason-c7e67059bb8ce7e126263471645c531d961b5e1d.tar.gz
mason-c7e67059bb8ce7e126263471645c531d961b5e1d.tar.bz2
mason-c7e67059bb8ce7e126263471645c531d961b5e1d.tar.lz
mason-c7e67059bb8ce7e126263471645c531d961b5e1d.tar.xz
mason-c7e67059bb8ce7e126263471645c531d961b5e1d.tar.zst
mason-c7e67059bb8ce7e126263471645c531d961b5e1d.zip
fix(ui): don't indent empty lines (#1597)
-rw-r--r--lua/mason-core/ui/display.lua19
-rw-r--r--tests/mason-core/ui_spec.lua20
2 files changed, 30 insertions, 9 deletions
diff --git a/lua/mason-core/ui/display.lua b/lua/mason-core/ui/display.lua
index 4c6a06c2..c4aebd95 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 40a8b888..17087045 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)