refacto: buffer management, setup fixes, autocmd fixes (#967)

This commit is contained in:
Kiyan
2022-02-14 19:16:45 +01:00
committed by GitHub
parent 3f4ed9b6c2
commit 6da7467944
11 changed files with 377 additions and 379 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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)

View File

@@ -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()