Skip to content

Commit 6d5a6fb

Browse files
committed
perf(#3257): replace view.initial_width with a function
1 parent ec0efb0 commit 6d5a6fb

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

lua/nvim-tree/view.lua

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ local function create_buffer(bufnr)
116116
events._dispatch_tree_attached_post(M.get_bufnr())
117117
end
118118

119-
---@param size (fun():integer)|integer|string
119+
---@param size nvim_tree.config.view.width.spec
120120
---@return integer
121121
local function get_size(size)
122122
if type(size) == "number" then
@@ -129,6 +129,16 @@ local function get_size(size)
129129
return math.floor(vim.o.columns * percent_as_decimal)
130130
end
131131

132+
---Return the width as per config
133+
---@return integer
134+
local function initial_width()
135+
if type(config.g.view.width) == "table" then
136+
return get_size(config.g.view.width.min or DEFAULT_MIN_WIDTH)
137+
else
138+
return get_size(config.g.view.width --[[@as nvim_tree.config.view.width.spec]])
139+
end
140+
end
141+
132142
---@param size (fun():integer)|integer|nil
133143
---@return integer
134144
local function get_width(size)
@@ -317,7 +327,7 @@ local function grow()
317327
padding = padding + wininfo[1].textoff
318328
end
319329

320-
local final_width = M.View.initial_width
330+
local final_width = initial_width()
321331
local max_width = get_width(M.View.max_width)
322332
if max_width == -1 then
323333
max_width = math.huge
@@ -606,7 +616,7 @@ function M.configure_width(width)
606616
M.configure_width(config.g.view.width)
607617
else
608618
-- otherwise - restore initial width
609-
M.View.width = M.View.initial_width
619+
M.View.width = initial_width()
610620
end
611621
else
612622
M.View.adaptive_size = false
@@ -624,8 +634,6 @@ function M.setup(opts)
624634
M.View.winopts.signcolumn = options.signcolumn
625635

626636
M.configure_width(options.width)
627-
628-
M.View.initial_width = get_width()
629637
end
630638

631639
return M

0 commit comments

Comments
 (0)