From a0c1d9d2b5be0a2eb0637766811af9f225d844ed Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Sat, 17 Apr 2021 21:03:22 +0200 Subject: [PATCH] fix: prevent_buffer_override - vim.schedule the buffer override autocmd to avoid being done before other ones thus failing some of the cursor movement - pcall the nvim_win_set_cursor to avoid failing when cursor is out of the window --- lua/nvim-tree/view.lua | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index ae5daa51..3757a90c 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -133,18 +133,20 @@ local goto_tbl = { } function M._prevent_buffer_override() - local curwin = a.nvim_get_current_win() - local curbuf = a.nvim_win_get_buf(curwin) - if curwin ~= M.View.winnr or curbuf == M.View.bufnr then return end + vim.schedule(function() + local curwin = a.nvim_get_current_win() + local curbuf = a.nvim_win_get_buf(curwin) + if curwin ~= M.View.winnr or curbuf == M.View.bufnr then return end - vim.cmd("buffer "..M.View.bufnr) + vim.cmd("buffer "..M.View.bufnr) - if #vim.api.nvim_list_wins() < 2 then - vim.cmd("vsplit") - else - vim.cmd("wincmd "..goto_tbl[M.View.side]) - end - vim.cmd("buffer "..curbuf) + if #vim.api.nvim_list_wins() < 2 then + vim.cmd("vsplit") + else + vim.cmd("wincmd "..goto_tbl[M.View.side]) + end + vim.cmd("buffer "..curbuf) + end) end function M.win_open() @@ -153,7 +155,7 @@ end function M.set_cursor(opts) if M.win_open() then - a.nvim_win_set_cursor(M.View.winnr, opts) + pcall(a.nvim_win_set_cursor, M.View.winnr, opts) end end