Skip to content

Commit 7a19c3e

Browse files
committed
fix: reschedule on_enter and setup autocmd
Wait for nvim to finish before checking buftypes. Fixes #944 Fixes #942
1 parent 92a64da commit 7a19c3e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Diff for: lua/nvim-tree.lua

+8-5
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ function M.on_enter(netrw_disabled)
103103
local lines = not is_dir and api.nvim_buf_get_lines(bufnr, 0, -1, false) or {}
104104
local buf_has_content = #lines > 1 or (#lines == 1 and lines[1] ~= "")
105105

106-
local should_open = _config.open_on_setup
107-
and ((is_dir and netrw_disabled) or (bufname == "" and not buf_has_content))
108-
and not vim.tbl_contains(ft_ignore, buftype)
106+
local buf_is_dir = is_dir and netrw_disabled
107+
local buf_is_empty = bufname == "" and not buf_has_content
108+
local should_be_preserved = vim.tbl_contains(ft_ignore, buftype)
109+
local should_open = _config.open_on_setup and not should_be_preserved and (buf_is_dir or buf_is_empty)
109110

110111
if should_open then
111112
M.hijack_current_window()
@@ -372,9 +373,11 @@ function M.setup(conf)
372373
require'nvim-tree.explorer'.setup(opts)
373374
require'nvim-tree.git'.setup(opts)
374375
setup_vim_commands()
375-
setup_autocommands(opts)
376376

377-
M.on_enter(netrw_disabled)
377+
vim.schedule(function()
378+
M.on_enter(netrw_disabled)
379+
setup_autocommands(opts)
380+
end)
378381
end
379382

380383
return M

0 commit comments

Comments
 (0)