Skip to content

Commit 83ece27

Browse files
committed
perf(#3257): remove view setup
1 parent 1730657 commit 83ece27

2 files changed

Lines changed: 35 additions & 32 deletions

File tree

lua/nvim-tree.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ function M.setup(config_user)
289289
end
290290

291291
require("nvim-tree.appearance").setup()
292-
require("nvim-tree.view").setup(config.g)
293292
require("nvim-tree.renderer.components").setup(config.g)
294293

295294
setup_autocommands()

lua/nvim-tree/view.lua

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,31 @@ local function initial_width()
139139
end
140140
end
141141

142+
---Configure width-related config
143+
---@param width string|function|number|table|nil
144+
function M.configure_width(width)
145+
log.line("dev", "configure_width")
146+
if type(width) == "table" then
147+
M.View.adaptive_size = true
148+
M.View.width = width.min or DEFAULT_MIN_WIDTH
149+
M.View.max_width = width.max or DEFAULT_MAX_WIDTH
150+
local lines_excluded = width.lines_excluded or DEFAULT_LINES_EXCLUDED
151+
M.View.root_excluded = vim.tbl_contains(lines_excluded, "root")
152+
M.View.padding = width.padding or DEFAULT_PADDING
153+
elseif width == nil then
154+
if config.g.view.width ~= nil then
155+
-- if we had input config - fallback to it
156+
M.configure_width(config.g.view.width)
157+
else
158+
-- otherwise - restore initial width
159+
M.View.width = initial_width()
160+
end
161+
else
162+
M.View.adaptive_size = false
163+
M.View.width = width
164+
end
165+
end
166+
142167
---@param size (fun():integer)|integer|nil
143168
---@return integer
144169
local function get_width(size)
@@ -198,7 +223,7 @@ local function open_win_config()
198223
if type(config.g.view.float.open_win_config) == "function" then
199224
return config.g.view.float.open_win_config()
200225
else
201-
return config.g.view.float.open_win_config --[[ @as vim.api.keyset.win_config ]]
226+
return config.g.view.float.open_win_config --[[@as vim.api.keyset.win_config]]
202227
end
203228
end
204229

@@ -305,6 +330,10 @@ function M.open(options)
305330
return
306331
end
307332

333+
if not M.View.width then
334+
M.configure_width(config.g.view.width)
335+
end
336+
308337
local profile = log.profile_start("view open")
309338

310339
events._dispatch_on_tree_pre_open()
@@ -420,6 +449,11 @@ end
420449
---@param opts OpenInWinOpts|nil
421450
function M.open_in_win(opts)
422451
opts = opts or { hijack_current_buf = true, resize = true }
452+
453+
if not M.View.width then
454+
M.configure_width(config.g.view.width)
455+
end
456+
423457
events._dispatch_on_tree_pre_open()
424458
if opts.winid and vim.api.nvim_win_is_valid(opts.winid) then
425459
vim.api.nvim_set_current_win(opts.winid)
@@ -606,34 +640,4 @@ function M.is_width_determined()
606640
return type(M.View.width) ~= "function"
607641
end
608642

609-
---Configure width-related config
610-
---@param width string|function|number|table|nil
611-
function M.configure_width(width)
612-
if type(width) == "table" then
613-
M.View.adaptive_size = true
614-
M.View.width = width.min or DEFAULT_MIN_WIDTH
615-
M.View.max_width = width.max or DEFAULT_MAX_WIDTH
616-
local lines_excluded = width.lines_excluded or DEFAULT_LINES_EXCLUDED
617-
M.View.root_excluded = vim.tbl_contains(lines_excluded, "root")
618-
M.View.padding = width.padding or DEFAULT_PADDING
619-
elseif width == nil then
620-
if config.g.view.width ~= nil then
621-
-- if we had input config - fallback to it
622-
M.configure_width(config.g.view.width)
623-
else
624-
-- otherwise - restore initial width
625-
M.View.width = initial_width()
626-
end
627-
else
628-
M.View.adaptive_size = false
629-
M.View.width = width
630-
end
631-
end
632-
633-
---@param opts nvim_tree.config
634-
function M.setup(opts)
635-
local options = opts.view or {}
636-
M.configure_width(options.width)
637-
end
638-
639643
return M

0 commit comments

Comments
 (0)