fix(picker.actions): close existing empty buffer if it's the current buffer

This commit is contained in:
Folke Lemaitre 2025-01-16 10:14:34 +01:00
parent de01218d1d
commit 0745505f2f
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -14,6 +14,13 @@ function M.edit(picker)
vim.cmd("normal! m'")
end)
local current_buf = vim.api.nvim_get_current_buf()
local current_empty = vim.bo[current_buf].buftype == ""
and vim.bo[current_buf].filetype == ""
and vim.api.nvim_buf_line_count(current_buf) == 1
and vim.api.nvim_buf_get_lines(current_buf, 0, -1, false)[1] == ""
and vim.api.nvim_buf_get_name(current_buf) == ""
local items = picker:selected({ fallback = true })
for _, item in ipairs(items) do
-- load the buffer
@ -43,6 +50,9 @@ function M.edit(picker)
-- center
vim.cmd("norm! zzzv")
end
if current_empty and vim.api.nvim_buf_is_valid(current_buf) then
vim.api.nvim_buf_delete(current_buf, { force = true })
end
end
M.cancel = function() end