fix: do not load cwd on each init call to avoid double rendering at startup when doing vim DIR
This commit is contained in:
@@ -128,10 +128,11 @@ function M.on_enter()
|
|||||||
local disable_netrw = vim.g.nvim_tree_disable_netrw or 1
|
local disable_netrw = vim.g.nvim_tree_disable_netrw or 1
|
||||||
local hijack_netrw = vim.g.nvim_tree_hijack_netrw or 1
|
local hijack_netrw = vim.g.nvim_tree_hijack_netrw or 1
|
||||||
if is_dir then
|
if is_dir then
|
||||||
api.nvim_command('lcd '..bufname)
|
lib.Tree.cwd = vim.fn.expand(bufname)
|
||||||
end
|
end
|
||||||
|
local netrw_disabled = hijack_netrw == 1 or disable_netrw == 1
|
||||||
local should_open = vim.g.nvim_tree_auto_open == 1
|
local should_open = vim.g.nvim_tree_auto_open == 1
|
||||||
and ((is_dir and (hijack_netrw == 1 or disable_netrw == 1)) or bufname == '')
|
and ((is_dir and netrw_disabled) or bufname == '')
|
||||||
and not vim.tbl_contains(ft_ignore, buftype)
|
and not vim.tbl_contains(ft_ignore, buftype)
|
||||||
lib.init(should_open, should_open)
|
lib.init(should_open, should_open)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ M.Tree = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function M.init(with_open, with_reload)
|
function M.init(with_open, with_reload)
|
||||||
|
if not M.Tree.cwd then
|
||||||
M.Tree.cwd = luv.cwd()
|
M.Tree.cwd = luv.cwd()
|
||||||
|
end
|
||||||
git.git_root(M.Tree.cwd)
|
git.git_root(M.Tree.cwd)
|
||||||
populate(M.Tree.entries, M.Tree.cwd)
|
populate(M.Tree.entries, M.Tree.cwd)
|
||||||
|
|
||||||
@@ -411,6 +413,7 @@ function M.change_dir(foldername)
|
|||||||
end
|
end
|
||||||
|
|
||||||
vim.cmd('lcd '..foldername)
|
vim.cmd('lcd '..foldername)
|
||||||
|
M.Tree.cwd = foldername
|
||||||
M.Tree.entries = {}
|
M.Tree.entries = {}
|
||||||
M.init(false, true)
|
M.init(false, true)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user