Skip to content

Commit 8567841

Browse files
authored
fix(#1946): only change vim's global cwd on startup when opening the tree (#1947)
1 parent e05ed6a commit 8567841

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lua/nvim-tree.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,6 @@ function M.on_enter(netrw_disabled)
267267
local stats = vim.loop.fs_stat(bufname)
268268
local is_dir = stats and stats.type == "directory"
269269
local is_file = stats and stats.type == "file"
270-
local cwd
271-
if is_dir then
272-
cwd = vim.fn.expand(vim.fn.fnameescape(bufname))
273-
-- INFO: could potentially conflict with rooter plugins
274-
vim.cmd("noautocmd cd " .. vim.fn.fnameescape(cwd))
275-
end
276270

277271
local lines = not is_dir and vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) or {}
278272
local buf_has_content = #lines > 1 or (#lines == 1 and lines[1] ~= "")
@@ -309,6 +303,13 @@ function M.on_enter(netrw_disabled)
309303
end
310304

311305
if should_open or should_hijack or existing_tree_wins[1] ~= nil then
306+
local cwd
307+
if is_dir then
308+
cwd = vim.fn.expand(vim.fn.fnameescape(bufname))
309+
-- INFO: could potentially conflict with rooter plugins
310+
vim.cmd("noautocmd cd " .. vim.fn.fnameescape(cwd))
311+
end
312+
312313
lib.open { path = cwd }
313314

314315
if should_focus_other_window then

0 commit comments

Comments
 (0)