Skip to content

Commit 9e7b8a3

Browse files
committed
perf(component): optimize left padding in component builder
1 parent 1571c7f commit 9e7b8a3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lua/astroui/status/component.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,11 @@ end
427427
-- @usage local heirline_component = require("astroui.status").components.builder({ { provider = "file_icon", opts = { padding = { right = 1 } } }, { provider = "filename" } })
428428
function M.builder(opts)
429429
opts = extend_tbl({ padding = { left = 0, right = 0 } }, opts)
430-
local children = {}
430+
local children, offset = {}, 0
431+
if opts.padding.left > 0 then -- add left padding
432+
table.insert(children, { provider = status_utils.pad_string(" ", { left = opts.padding.left - 1 }) })
433+
offset = offset + 1
434+
end
431435
for key, entry in pairs(opts) do
432436
if
433437
type(key) == "number"
@@ -437,11 +441,9 @@ function M.builder(opts)
437441
then
438442
entry.provider = provider[entry.provider](entry.opts)
439443
end
444+
if type(key) == "number" then key = key + offset end
440445
children[key] = entry
441446
end
442-
if opts.padding.left > 0 then -- add left padding
443-
table.insert(children, 1, { provider = status_utils.pad_string(" ", { left = opts.padding.left - 1 }) })
444-
end
445447
if opts.padding.right > 0 then -- add right padding
446448
table.insert(children, { provider = status_utils.pad_string(" ", { right = opts.padding.right - 1 }) })
447449
end

0 commit comments

Comments
 (0)