refactor(#2826): move autocmds to Explorer

This commit is contained in:
Alexander Courtis
2025-04-21 12:17:21 +10:00
parent 44cb3d2f0a
commit 3a82885cc3
2 changed files with 28 additions and 35 deletions

View File

@@ -91,6 +91,18 @@ function Explorer:create_autocmds()
end,
})
if self.opts.view.float.enable and self.opts.view.float.quit_on_focus_loss then
vim.api.nvim_create_autocmd("WinLeave", {
group = self.augroup_id,
pattern = "NvimTree_*",
callback = function()
if utils.is_nvim_tree_buf(0) then
self.view:close()
end
end,
})
end
vim.api.nvim_create_autocmd("BufWritePost", {
group = self.augroup_id,
callback = function()
@@ -143,6 +155,22 @@ function Explorer:create_autocmds()
end,
})
-- prevent new opened file from opening in the same window as nvim-tree
vim.api.nvim_create_autocmd("BufWipeout", {
group = self.augroup_id,
pattern = "NvimTree_*",
callback = function()
if not utils.is_nvim_tree_buf(0) then
return
end
if self.opts.actions.open_file.eject then
self.view:prevent_buffer_override()
else
self.view:abandon_current_window()
end
end,
})
vim.api.nvim_create_autocmd("BufEnter", {
group = self.augroup_id,
pattern = "NvimTree_*",