fix(dirchange): do not change dir when switching windows

- Avoid changing dir when switching windows, except when
changing tabpage.
- Load nvim-tree with passed directory when opening with `nvim DIR`

Fixes #858 #720
This commit is contained in:
kiyan
2021-12-24 14:50:20 +01:00
parent e49bd8ffd3
commit 0a2f6b0b6b
2 changed files with 7 additions and 2 deletions

View File

@@ -455,12 +455,17 @@ function M.collapse_all()
M.redraw()
end
local current_tab = api.nvim_get_current_tabpage()
function M.change_dir(name)
local foldername = name == '..' and vim.fn.fnamemodify(M.Tree.cwd, ':h') or name
local no_cwd_change = vim.fn.expand(foldername) == M.Tree.cwd
if no_cwd_change then
local new_tab = api.nvim_get_current_tabpage()
local is_window = vim.v.event.scope == "window" and new_tab == current_tab
if no_cwd_change or is_window then
return
end
current_tab = new_tab
vim.cmd('lcd '..vim.fn.fnameescape(foldername))
M.init(false, foldername)