From 0cdfa1dfbbfc8fda340054915991fda188db8d8e Mon Sep 17 00:00:00 2001 From: siduck Date: Sat, 14 Dec 2024 15:59:13 +0530 Subject: [PATCH] fix(border): add whitespace to align border --- lua/volt/ui/components.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lua/volt/ui/components.lua b/lua/volt/ui/components.lua index 97a6329..5ab5906 100644 --- a/lua/volt/ui/components.lua +++ b/lua/volt/ui/components.lua @@ -71,11 +71,22 @@ M.border = function(lines, hl) hl = hl or "linenr" local maxw = 0 + local line_widths = {} - for i, line in ipairs(lines) do - maxw = math.max(maxw, M.line_w(line)) + for _, line in ipairs(lines) do + local linew = M.line_w(line) + + if maxw < linew then + maxw = linew + end + + table.insert(line_widths, linew) + end + + for i, _ in ipairs(lines) do table.insert(lines[i], 1, { "│ ", hl }) - table.insert(lines[i], { " │", hl }) + local rpad = string.rep(" ", maxw - line_widths[i]) + table.insert(lines[i], { rpad .. " │", hl }) end maxw = maxw + 2