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()
else
if vim.g.nvim_tree_follow == 1 then
vim.schedule(function() M.find_file(true) end)
M.find_file(true)
else
vim.schedule(lib.open)
lib.open()
end
end
end
@@ -28,17 +28,12 @@ function M.close()
end
end
function M.open(cb)
vim.schedule(
function()
function M.open()
if not lib.win_open() then
lib.open()
else
lib.set_target_win()
end
pcall(cb)
end
)
end
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
vim.defer_fn(function()
if M.close() then
M.open(function()
M.open()
api.nvim_command('wincmd '..winopts.open_command)
end)
end
end, 1)
end
@@ -82,7 +76,7 @@ local keypress_funcs = {
prev_git_item = gen_go_to('prev_git_item'),
next_git_item = gen_go_to('next_git_item'),
dir_up = lib.dir_up,
close = function(node) M.close() end,
close = function() M.close() end,
preview = function(node)
if node.entries ~= nil or node.name == '..' then return end
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')
if with_open then
return M.open(
function()
M.open()
lib.win_focus()
if not is_file_readable(filepath) then return end
lib.set_index_and_redraw(filepath)
end
)
return
end
if not is_file_readable(filepath) then return end

View File

@@ -155,8 +155,6 @@ local function refresh_nodes(node)
end
function M.refresh_tree()
vim.schedule(
function ()
if vim.v.exiting ~= nil then return end
refresh_nodes(M.Tree)
@@ -170,7 +168,6 @@ function M.refresh_tree()
else
M.Tree.loaded = false
end
end)
end
function M.set_index_and_redraw(fname)