diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 7bb3f301..09e1018f 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -380,10 +380,11 @@ function M.setup(conf) require'nvim-tree.diagnostics'.setup(opts) require'nvim-tree.explorer'.setup(opts) require'nvim-tree.git'.setup(opts) + require'nvim-tree.view'.setup(opts) setup_vim_commands() vim.schedule(function() - require'nvim-tree.view'.setup(opts) + require'nvim-tree.view'.create_buffer() M.on_enter(netrw_disabled) setup_autocommands(opts) end) diff --git a/lua/nvim-tree/renderer/init.lua b/lua/nvim-tree/renderer/init.lua index e9fe576d..258541c6 100644 --- a/lua/nvim-tree/renderer/init.lua +++ b/lua/nvim-tree/renderer/init.lua @@ -371,7 +371,9 @@ end local M = {} function M.draw() - if not api.nvim_buf_is_loaded(view.View.bufnr) then return end + if not TreeExplorer or not api.nvim_buf_is_loaded(view.View.bufnr) then + return + end local cursor if view.win_open() then cursor = api.nvim_win_get_cursor(view.get_winnr()) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index 52865878..b5075ba2 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -50,7 +50,7 @@ local function wipe_rogue_buffer() end end -local function create_buffer() +function M.create_buffer() wipe_rogue_buffer() M.View.bufnr = a.nvim_create_buf(false, false) a.nvim_buf_set_name(M.View.bufnr, 'NvimTree') @@ -82,7 +82,6 @@ function M.setup(opts) M.View.winopts.number = options.number M.View.winopts.relativenumber = options.relativenumber M.View.winopts.signcolumn = options.signcolumn - create_buffer() end local move_cmd = { @@ -222,7 +221,7 @@ local function open_window() end local function is_buf_valid(bufnr) - return a.nvim_buf_is_valid(bufnr) and a.nvim_buf_is_loaded(bufnr) + return bufnr and a.nvim_buf_is_valid(bufnr) and a.nvim_buf_is_loaded(bufnr) end function M.open(options) @@ -230,7 +229,7 @@ function M.open(options) local should_redraw = false if not is_buf_valid(M.View.bufnr) then should_redraw = true - create_buffer() + M.create_buffer() end if not M.win_open() then