Skip to content

Commit a0c1d9d

Browse files
committed
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
1 parent 3d2144c commit a0c1d9d

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lua/nvim-tree/view.lua

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,20 @@ local goto_tbl = {
133133
}
134134

135135
function M._prevent_buffer_override()
136-
local curwin = a.nvim_get_current_win()
137-
local curbuf = a.nvim_win_get_buf(curwin)
138-
if curwin ~= M.View.winnr or curbuf == M.View.bufnr then return end
136+
vim.schedule(function()
137+
local curwin = a.nvim_get_current_win()
138+
local curbuf = a.nvim_win_get_buf(curwin)
139+
if curwin ~= M.View.winnr or curbuf == M.View.bufnr then return end
139140

140-
vim.cmd("buffer "..M.View.bufnr)
141+
vim.cmd("buffer "..M.View.bufnr)
141142

142-
if #vim.api.nvim_list_wins() < 2 then
143-
vim.cmd("vsplit")
144-
else
145-
vim.cmd("wincmd "..goto_tbl[M.View.side])
146-
end
147-
vim.cmd("buffer "..curbuf)
143+
if #vim.api.nvim_list_wins() < 2 then
144+
vim.cmd("vsplit")
145+
else
146+
vim.cmd("wincmd "..goto_tbl[M.View.side])
147+
end
148+
vim.cmd("buffer "..curbuf)
149+
end)
148150
end
149151

150152
function M.win_open()
@@ -153,7 +155,7 @@ end
153155

154156
function M.set_cursor(opts)
155157
if M.win_open() then
156-
a.nvim_win_set_cursor(M.View.winnr, opts)
158+
pcall(a.nvim_win_set_cursor, M.View.winnr, opts)
157159
end
158160
end
159161

0 commit comments

Comments
 (0)