refacto: buffer management, setup fixes, autocmd fixes (#967)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
local a = vim.api
|
||||
local lib = function() return require'nvim-tree.lib' end
|
||||
local utils = require'nvim-tree.utils'
|
||||
|
||||
local M = {
|
||||
@@ -9,7 +8,7 @@ local M = {
|
||||
}
|
||||
}
|
||||
|
||||
function M.fn(name)
|
||||
function M.fn(name, with_open)
|
||||
if not TreeExplorer then return end
|
||||
|
||||
local foldername = name == '..' and vim.fn.fnamemodify(utils.path_remove_trailing(TreeExplorer.cwd), ':h') or name
|
||||
@@ -20,13 +19,18 @@ function M.fn(name)
|
||||
return
|
||||
end
|
||||
M.current_tab = new_tab
|
||||
M.force_dirchange(foldername, with_open)
|
||||
end
|
||||
|
||||
if M.options.global then
|
||||
vim.cmd('cd '..vim.fn.fnameescape(foldername))
|
||||
else
|
||||
vim.cmd('lcd '..vim.fn.fnameescape(foldername))
|
||||
function M.force_dirchange(foldername, with_open)
|
||||
if vim.tbl_isempty(vim.v.event) then
|
||||
if M.options.global then
|
||||
vim.cmd('cd '..vim.fn.fnameescape(foldername))
|
||||
else
|
||||
vim.cmd('lcd '..vim.fn.fnameescape(foldername))
|
||||
end
|
||||
end
|
||||
lib().init(false, foldername)
|
||||
require'nvim-tree.lib'.init(with_open, foldername)
|
||||
end
|
||||
|
||||
function M.setup(options)
|
||||
|
||||
@@ -56,7 +56,7 @@ function M.fn(fname)
|
||||
if tree_altered then
|
||||
renderer.draw()
|
||||
end
|
||||
if index and view.win_open() then
|
||||
if index and view.is_visible() then
|
||||
view.set_cursor({index, 0})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -156,6 +156,7 @@ function M.setup(opts)
|
||||
require'nvim-tree.actions.system-open'.setup(opts.system_open)
|
||||
require'nvim-tree.actions.trash'.setup(opts.trash)
|
||||
require'nvim-tree.actions.open-file'.setup(opts)
|
||||
require'nvim-tree.actions.change-dir'.setup(opts)
|
||||
|
||||
local user_map_config = (opts.view or {}).mappings or {}
|
||||
local options = vim.tbl_deep_extend('force', DEFAULT_MAPPING_CONFIG, user_map_config)
|
||||
|
||||
@@ -41,7 +41,7 @@ function M.reload_explorer(callback)
|
||||
|
||||
git.reload(function(projects)
|
||||
refresh_nodes(TreeExplorer, projects)
|
||||
if view.win_open() then
|
||||
if view.is_visible() then
|
||||
renderer.draw()
|
||||
if callback and type(callback) == 'function' then
|
||||
callback()
|
||||
|
||||
Reference in New Issue
Block a user