refactor(#2826): move autocmds to Explorer
This commit is contained in:
parent
44cb3d2f0a
commit
3a82885cc3
@ -148,26 +148,6 @@ local function setup_autocommands(opts)
|
|||||||
vim.api.nvim_create_autocmd(name, vim.tbl_extend("force", default_opts, custom_opts))
|
vim.api.nvim_create_autocmd(name, vim.tbl_extend("force", default_opts, custom_opts))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO #2826 move this to explorer
|
|
||||||
-- prevent new opened file from opening in the same window as nvim-tree
|
|
||||||
create_nvim_tree_autocmd("BufWipeout", {
|
|
||||||
pattern = "NvimTree_*",
|
|
||||||
callback = function()
|
|
||||||
if not utils.is_nvim_tree_buf(0) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local explorer = core.get_explorer()
|
|
||||||
if explorer then
|
|
||||||
if opts.actions.open_file.eject then
|
|
||||||
explorer.view:prevent_buffer_override()
|
|
||||||
else
|
|
||||||
explorer.view:abandon_current_window()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
if opts.tab.sync.open then
|
if opts.tab.sync.open then
|
||||||
create_nvim_tree_autocmd("TabEnter", { callback = vim.schedule_wrap(M.tab_enter) })
|
create_nvim_tree_autocmd("TabEnter", { callback = vim.schedule_wrap(M.tab_enter) })
|
||||||
end
|
end
|
||||||
@ -229,21 +209,6 @@ local function setup_autocommands(opts)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO #2826 move this to explorer
|
|
||||||
if opts.view.float.enable and opts.view.float.quit_on_focus_loss then
|
|
||||||
create_nvim_tree_autocmd("WinLeave", {
|
|
||||||
pattern = "NvimTree_*",
|
|
||||||
callback = function()
|
|
||||||
if utils.is_nvim_tree_buf(0) then
|
|
||||||
local explorer = core.get_explorer()
|
|
||||||
if explorer then
|
|
||||||
explorer.view:close()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Handles event dispatch when tree is closed by `:q`
|
-- Handles event dispatch when tree is closed by `:q`
|
||||||
create_nvim_tree_autocmd("WinClosed", {
|
create_nvim_tree_autocmd("WinClosed", {
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
|
|||||||
@ -91,6 +91,18 @@ function Explorer:create_autocmds()
|
|||||||
end,
|
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", {
|
vim.api.nvim_create_autocmd("BufWritePost", {
|
||||||
group = self.augroup_id,
|
group = self.augroup_id,
|
||||||
callback = function()
|
callback = function()
|
||||||
@ -143,6 +155,22 @@ function Explorer:create_autocmds()
|
|||||||
end,
|
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", {
|
vim.api.nvim_create_autocmd("BufEnter", {
|
||||||
group = self.augroup_id,
|
group = self.augroup_id,
|
||||||
pattern = "NvimTree_*",
|
pattern = "NvimTree_*",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user