fix: close windows properly (#924)
This commit is contained in:
@@ -6,6 +6,14 @@ local events = require'nvim-tree.events'
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
local function close_windows(windows)
|
||||||
|
for _, window in ipairs(windows) do
|
||||||
|
if a.nvim_win_is_valid(window) then
|
||||||
|
a.nvim_win_close(window, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function clear_buffer(absolute_path)
|
local function clear_buffer(absolute_path)
|
||||||
local bufs = vim.fn.getbufinfo({bufloaded = 1, buflisted = 1})
|
local bufs = vim.fn.getbufinfo({bufloaded = 1, buflisted = 1})
|
||||||
for _, buf in pairs(bufs) do
|
for _, buf in pairs(bufs) do
|
||||||
@@ -16,10 +24,8 @@ local function clear_buffer(absolute_path)
|
|||||||
vim.cmd(':bn')
|
vim.cmd(':bn')
|
||||||
a.nvim_set_current_win(winnr)
|
a.nvim_set_current_win(winnr)
|
||||||
end
|
end
|
||||||
vim.api.nvim_buf_delete(buf.bufnr, { force = true })
|
a.nvim_buf_delete(buf.bufnr, { force = true })
|
||||||
if buf.windows[1] and vim.api.nvim_win_is_valid(buf.bufnr) then
|
close_windows(buf.windows)
|
||||||
vim.api.nvim_win_close(buf.windows[1], true)
|
|
||||||
end
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
local has_notify, notify = pcall(require, 'notify')
|
||||||
|
|
||||||
local a = vim.api
|
local a = vim.api
|
||||||
local uv = vim.loop
|
local uv = vim.loop
|
||||||
|
|
||||||
@@ -11,7 +13,11 @@ end
|
|||||||
|
|
||||||
function M.warn(msg)
|
function M.warn(msg)
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
|
if has_notify then
|
||||||
|
notify(msg, vim.log.levels.WARN, { title = "NvimTree" })
|
||||||
|
else
|
||||||
vim.notify("[NvimTree] "..msg, vim.log.levels.WARN)
|
vim.notify("[NvimTree] "..msg, vim.log.levels.WARN)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user