@@ -139,6 +139,31 @@ local function initial_width()
139139 end
140140end
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
144169local 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
203228end
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 ()
420449--- @param opts OpenInWinOpts | nil
421450function 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"
607641end
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-
639643return M
0 commit comments