chore: remove async to avoid unecessary complexity (#277)

This commit is contained in:
Kiyan
2021-04-08 22:36:17 +02:00
committed by GitHub
parent bbb8d6070f
commit 81269a6eba
2 changed files with 27 additions and 38 deletions

View File

@@ -14,9 +14,9 @@ function M.toggle()
lib.close() lib.close()
else else
if vim.g.nvim_tree_follow == 1 then if vim.g.nvim_tree_follow == 1 then
vim.schedule(function() M.find_file(true) end) M.find_file(true)
else else
vim.schedule(lib.open) lib.open()
end end
end end
end end
@@ -28,17 +28,12 @@ function M.close()
end end
end end
function M.open(cb) function M.open()
vim.schedule( if not lib.win_open() then
function() lib.open()
if not lib.win_open() then else
lib.open() lib.set_target_win()
else end
lib.set_target_win()
end
pcall(cb)
end
)
end end
local winopts = config.window_options() local winopts = config.window_options()
@@ -46,9 +41,8 @@ function M.tab_change()
-- we need defer_fn to make sure we close/open after we enter the tab -- we need defer_fn to make sure we close/open after we enter the tab
vim.defer_fn(function() vim.defer_fn(function()
if M.close() then if M.close() then
M.open(function() M.open()
api.nvim_command('wincmd '..winopts.open_command) api.nvim_command('wincmd '..winopts.open_command)
end)
end end
end, 1) end, 1)
end end
@@ -82,7 +76,7 @@ local keypress_funcs = {
prev_git_item = gen_go_to('prev_git_item'), prev_git_item = gen_go_to('prev_git_item'),
next_git_item = gen_go_to('next_git_item'), next_git_item = gen_go_to('next_git_item'),
dir_up = lib.dir_up, dir_up = lib.dir_up,
close = function(node) M.close() end, close = function() M.close() end,
preview = function(node) preview = function(node)
if node.entries ~= nil or node.name == '..' then return end if node.entries ~= nil or node.name == '..' then return end
return lib.open_file('preview', node.absolute_path) return lib.open_file('preview', node.absolute_path)
@@ -153,13 +147,11 @@ function M.find_file(with_open)
local filepath = vim.fn.fnamemodify(bufname, ':p') local filepath = vim.fn.fnamemodify(bufname, ':p')
if with_open then if with_open then
return M.open( M.open()
function() lib.win_focus()
lib.win_focus() if not is_file_readable(filepath) then return end
if not is_file_readable(filepath) then return end lib.set_index_and_redraw(filepath)
lib.set_index_and_redraw(filepath) return
end
)
end end
if not is_file_readable(filepath) then return end if not is_file_readable(filepath) then return end

View File

@@ -155,22 +155,19 @@ local function refresh_nodes(node)
end end
function M.refresh_tree() function M.refresh_tree()
vim.schedule( if vim.v.exiting ~= nil then return end
function ()
if vim.v.exiting ~= nil then return end
refresh_nodes(M.Tree) refresh_nodes(M.Tree)
if config.get_icon_state().show_git_icon or vim.g.nvim_tree_git_hl == 1 then if config.get_icon_state().show_git_icon or vim.g.nvim_tree_git_hl == 1 then
git.reload_roots() git.reload_roots()
refresh_git(M.Tree) refresh_git(M.Tree)
end end
if M.win_open() then if M.win_open() then
renderer.draw(M.Tree, true) renderer.draw(M.Tree, true)
else else
M.Tree.loaded = false M.Tree.loaded = false
end end
end)
end end
function M.set_index_and_redraw(fname) function M.set_index_and_redraw(fname)