refacto: remove rendering from lib.init

This commit is contained in:
kiyan
2022-02-20 23:01:25 +01:00
parent 9008bac180
commit 58b81ed9e6
3 changed files with 11 additions and 9 deletions

View File

@@ -26,7 +26,7 @@ function M.toggle(find_file, no_focus)
else else
local previous_buf = api.nvim_get_current_buf() local previous_buf = api.nvim_get_current_buf()
M.open() M.open()
if TreeExplorer and (_config.update_focused_file.enable or find_file) then if _config.update_focused_file.enable or find_file then
M.find_file(false, previous_buf) M.find_file(false, previous_buf)
end end
if no_focus then if no_focus then
@@ -200,7 +200,8 @@ function M.on_enter(netrw_disabled)
end end
if should_open or should_hijack or existing_tree_wins[1] ~= nil then if should_open or should_hijack or existing_tree_wins[1] ~= nil then
lib.init(true, cwd) lib.init(cwd)
lib.open()
end end
M.initialized = true M.initialized = true
end end

View File

@@ -30,8 +30,12 @@ function M.force_dirchange(foldername, with_open)
vim.cmd('lcd '..vim.fn.fnameescape(foldername)) vim.cmd('lcd '..vim.fn.fnameescape(foldername))
end end
end end
require'nvim-tree.lib'.init(with_open, foldername) require'nvim-tree.lib'.init(foldername)
if with_open then
require"nvim-tree.lib".open()
else
require"nvim-tree.renderer".draw() require"nvim-tree.renderer".draw()
end
end end
function M.setup(options) function M.setup(options)

View File

@@ -14,13 +14,10 @@ local M = {
TreeExplorer = nil TreeExplorer = nil
function M.init(with_open, foldername) function M.init(foldername)
local init_done = false local init_done = false
TreeExplorer = explorer.Explorer.new(foldername) TreeExplorer = explorer.Explorer.new(foldername)
TreeExplorer:init(function() TreeExplorer:init(function()
if with_open then
M.open()
end
init_done = true init_done = true
if not first_init_done then if not first_init_done then
events._dispatch_ready() events._dispatch_ready()
@@ -138,7 +135,7 @@ end
function M.open(cwd) function M.open(cwd)
M.set_target_win() M.set_target_win()
if not TreeExplorer or cwd then if not TreeExplorer or cwd then
return M.init(true, cwd or vim.loop.cwd()) M.init(cwd or vim.loop.cwd())
end end
if should_hijack_current_buf() then if should_hijack_current_buf() then
view.open_in_current_win() view.open_in_current_win()