From 2e95b9d42467168185cc5a505ef4288de4c5670f Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Fri, 3 Feb 2023 13:53:01 -0800 Subject: [PATCH] fix: edge case where opening a file would delete its contents --- lua/oil/util.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/oil/util.lua b/lua/oil/util.lua index d6bad474..156aa5b7 100644 --- a/lua/oil/util.lua +++ b/lua/oil/util.lua @@ -111,11 +111,15 @@ M.rename_buffer = function(src_bufnr, dest_buf_name) end end + local is_modified = vim.bo[src_bufnr].modified local dest_bufnr = vim.fn.bufadd(dest_buf_name) pcall(vim.fn.bufload, dest_bufnr) if vim.bo[src_bufnr].buflisted then vim.bo[dest_bufnr].buflisted = true 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 -- actually in the window. We need to wait to enter the buffer and _then_ replace it. vim.schedule(function()