feat(nvim-tree): close when last window
This commit is contained in:
@@ -7,11 +7,7 @@ local function override_highlights()
|
||||
|
||||
-- Symlink Icon
|
||||
hl = utils.get_hl_source("NvimTreeSymlinkIcon")
|
||||
vim.api.nvim_set_hl(
|
||||
0,
|
||||
"NvimTreeSymlinkIcon",
|
||||
{ fg = hl.fg, bg = nil }
|
||||
)
|
||||
vim.api.nvim_set_hl(0, "NvimTreeSymlinkIcon", { fg = hl.fg, bg = nil })
|
||||
end
|
||||
|
||||
local function disable_highlights()
|
||||
@@ -251,5 +247,29 @@ return {
|
||||
find_file = true,
|
||||
focus = false,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("QuitPre", {
|
||||
callback = function()
|
||||
local tree_wins = {}
|
||||
local floating_wins = {}
|
||||
local wins = vim.api.nvim_list_wins()
|
||||
for _, w in ipairs(wins) do
|
||||
local bufname =
|
||||
vim.api.nvim_buf_get_name(vim.api.nvim_win_get_buf(w))
|
||||
if bufname:match("NvimTree_") ~= nil then
|
||||
table.insert(tree_wins, w)
|
||||
end
|
||||
if vim.api.nvim_win_get_config(w).relative ~= "" then
|
||||
table.insert(floating_wins, w)
|
||||
end
|
||||
end
|
||||
if 1 == #wins - #floating_wins - #tree_wins then
|
||||
-- Should quit, so we close all invalid windows.
|
||||
for _, w in ipairs(tree_wins) do
|
||||
vim.api.nvim_win_close(w, true)
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user