fix: edge case where opening a file would delete its contents
This commit is contained in:
parent
716dd8f9cf
commit
2e95b9d424
1 changed files with 4 additions and 0 deletions
|
|
@ -111,11 +111,15 @@ M.rename_buffer = function(src_bufnr, dest_buf_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local is_modified = vim.bo[src_bufnr].modified
|
||||||
local dest_bufnr = vim.fn.bufadd(dest_buf_name)
|
local dest_bufnr = vim.fn.bufadd(dest_buf_name)
|
||||||
pcall(vim.fn.bufload, dest_bufnr)
|
pcall(vim.fn.bufload, dest_bufnr)
|
||||||
if vim.bo[src_bufnr].buflisted then
|
if vim.bo[src_bufnr].buflisted then
|
||||||
vim.bo[dest_bufnr].buflisted = true
|
vim.bo[dest_bufnr].buflisted = true
|
||||||
end
|
end
|
||||||
|
-- If the src_bufnr was marked as modified by the previous operation, we should undo that
|
||||||
|
vim.bo[src_bufnr].modified = is_modified
|
||||||
|
|
||||||
-- If we're renaming a buffer that we're about to enter, this may be called before the buffer is
|
-- If we're renaming a buffer that we're about to enter, this may be called before the buffer is
|
||||||
-- actually in the window. We need to wait to enter the buffer and _then_ replace it.
|
-- actually in the window. We need to wait to enter the buffer and _then_ replace it.
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue