fix: run find_file on DirChanged if update_focused_file is enabled

fixes #690
This commit is contained in:
kiyan
2021-10-05 17:51:48 +02:00
parent 29e5b754b7
commit 7ca37f824b

View File

@@ -255,15 +255,15 @@ function M.find_file(with_open)
local bufname = vim.fn.bufname() local bufname = vim.fn.bufname()
local bufnr = api.nvim_get_current_buf() local bufnr = api.nvim_get_current_buf()
local filepath = vim.fn.fnamemodify(bufname, ':p') local filepath = vim.fn.fnamemodify(bufname, ':p')
if not is_file_readable(filepath) then
return
end
if with_open then if with_open then
M.open() M.open()
view.focus() view.focus()
end end
if not is_file_readable(filepath) then
return
end
update_base_dir_with_filepath(filepath, bufnr) update_base_dir_with_filepath(filepath, bufnr)
lib.set_index_and_redraw(filepath) lib.set_index_and_redraw(filepath)
end end
@@ -364,6 +364,14 @@ local function setup_vim_commands()
]] ]]
end end
function M.change_dir(name)
lib.change_dir(name)
if _config.update_focused_file.enable then
M.find_file(false)
end
end
local function setup_autocommands(opts) local function setup_autocommands(opts)
vim.cmd "augroup NvimTree" vim.cmd "augroup NvimTree"
vim.cmd [[ vim.cmd [[
@@ -387,7 +395,7 @@ local function setup_autocommands(opts)
vim.cmd "au CursorMoved NvimTree lua require'nvim-tree'.place_cursor_on_node()" vim.cmd "au CursorMoved NvimTree lua require'nvim-tree'.place_cursor_on_node()"
end end
if opts.update_cwd then if opts.update_cwd then
vim.cmd "au DirChanged * lua require'nvim-tree.lib'.change_dir(vim.loop.cwd())" vim.cmd "au DirChanged * lua require'nvim-tree'.change_dir(vim.loop.cwd())"
end end
if opts.update_focused_file.enable then if opts.update_focused_file.enable then
vim.cmd "au BufEnter * lua require'nvim-tree'.find_file(false)" vim.cmd "au BufEnter * lua require'nvim-tree'.find_file(false)"