From d1323e5dd37a632f4c25c95db897314abe79f69d Mon Sep 17 00:00:00 2001 From: Lukas Reineke Date: Sun, 10 Nov 2024 14:50:00 +0900 Subject: [PATCH] fix: leadmultispace and multispace fix #939 --- lua/ibl/virt_text.lua | 2 +- specs/features/virt_text_spec.lua | 41 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lua/ibl/virt_text.lua b/lua/ibl/virt_text.lua index 87fcb85c..14beb6a6 100644 --- a/lua/ibl/virt_text.lua +++ b/lua/ibl/virt_text.lua @@ -84,7 +84,7 @@ M.get = function( local indent_hl local underline_hl local sa = scope_active - local char = get_char(char_map[ws], indent_index) + local char = get_char(char_map[ws], (ws == whitespace.SPACE and i) or indent_index) if indent.is_indent(ws) then whitespace_hl = utils.tbl_get_index(highlights.whitespace, indent_index).char diff --git a/specs/features/virt_text_spec.lua b/specs/features/virt_text_spec.lua index 36baa7e1..e5f2e77f 100644 --- a/specs/features/virt_text_spec.lua +++ b/specs/features/virt_text_spec.lua @@ -695,4 +695,45 @@ describe("virt_text", function() { "e", { "@ibl.whitespace.char.3", "@ibl.scope.underline.2" } }, }) end) + + it("renders lead and multi lead spaces correctly", function() + local config = conf.set_config() + highlights.setup() + local char_map = { + [TAB_START] = "a", + [TAB_START_SINGLE] = "b", + [TAB_FILL] = "c", + [TAB_END] = "d", + [SPACE] = { "e", "f", "g" }, + [INDENT] = "h", + } + local whitespace_tbl = { INDENT, SPACE, SPACE, SPACE, INDENT, SPACE, SPACE, SPACE } + local scope_active = false + local scope_index = -1 + local scope_start = false + local scope_end = false + local scope_col_start_single = 0 + + local virt_text = vt.get( + config, + char_map, + whitespace_tbl, + scope_active, + scope_index, + scope_start, + scope_end, + scope_col_start_single + ) + + assert.are.same(virt_text, { + { "h", { "@ibl.whitespace.char.1", "@ibl.indent.char.1" } }, + { "f", { "@ibl.whitespace.char.1" } }, + { "g", { "@ibl.whitespace.char.1" } }, + { "e", { "@ibl.whitespace.char.1" } }, + { "h", { "@ibl.whitespace.char.1", "@ibl.indent.char.1" } }, + { "g", { "@ibl.whitespace.char.1" } }, + { "e", { "@ibl.whitespace.char.1" } }, + { "f", { "@ibl.whitespace.char.1" } }, + }) + end) end)