Skip to content

Commit 4af5722

Browse files
authored
fix(#1989): cut/paste over open buffer (#2279)
* fix(#1989): cut/paste overwrite deletes destination buffer * fix(#1989): cut/paste overwrite deletes destination buffer
1 parent d17389c commit 4af5722

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lua/nvim-tree/utils.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ function M.get_nodes_by_line(nodes_all, line_start)
161161
end
162162

163163
function M.rename_loaded_buffers(old_path, new_path)
164+
-- delete new if it exists
165+
for _, buf in pairs(vim.api.nvim_list_bufs()) do
166+
if vim.api.nvim_buf_is_loaded(buf) then
167+
local buf_name = vim.api.nvim_buf_get_name(buf)
168+
if buf_name == new_path then
169+
vim.api.nvim_buf_delete(buf, { force = true })
170+
end
171+
end
172+
end
173+
174+
-- rename old to new
164175
for _, buf in pairs(vim.api.nvim_list_bufs()) do
165176
if vim.api.nvim_buf_is_loaded(buf) then
166177
local buf_name = vim.api.nvim_buf_get_name(buf)

0 commit comments

Comments
 (0)