fix: close windows properly (#924)

This commit is contained in:
Lopi-py
2022-02-17 02:19:42 -05:00
committed by GitHub
parent 06cabd5559
commit 5f047bc5f9
2 changed files with 17 additions and 5 deletions

View File

@@ -6,6 +6,14 @@ local events = require'nvim-tree.events'
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 bufs = vim.fn.getbufinfo({bufloaded = 1, buflisted = 1})
for _, buf in pairs(bufs) do
@@ -16,10 +24,8 @@ local function clear_buffer(absolute_path)
vim.cmd(':bn')
a.nvim_set_current_win(winnr)
end
vim.api.nvim_buf_delete(buf.bufnr, { force = true })
if buf.windows[1] and vim.api.nvim_win_is_valid(buf.bufnr) then
vim.api.nvim_win_close(buf.windows[1], true)
end
a.nvim_buf_delete(buf.bufnr, { force = true })
close_windows(buf.windows)
return
end
end

View File

@@ -1,3 +1,5 @@
local has_notify, notify = pcall(require, 'notify')
local a = vim.api
local uv = vim.loop
@@ -11,7 +13,11 @@ end
function M.warn(msg)
vim.schedule(function()
vim.notify("[NvimTree] "..msg, vim.log.levels.WARN)
if has_notify then
notify(msg, vim.log.levels.WARN, { title = "NvimTree" })
else
vim.notify("[NvimTree] "..msg, vim.log.levels.WARN)
end
end)
end