From fe16993262fc85a209a3a1acdb4eac8a35c6ed96 Mon Sep 17 00:00:00 2001 From: Barrett Ruth <62671086+barrettruth@users.noreply.github.com> Date: Sat, 21 Feb 2026 02:43:59 -0500 Subject: [PATCH] fix(preview): prevent preview from re-initializing modified oil buffers (#12) Problem: when the preview window opens a directory that already has a loaded oil buffer with unsaved edits, open_preview() unconditionally calls load_oil_buffer() on it. This re-initializes the buffer via view.initialize() -> render_buffer_async(), which re-fetches the directory listing from disk and replaces all buffer lines, destroying the user's pending edits. The mutation parser then can't see the deleted entry in the source buffer, so it produces a COPY action instead of a MOVE. Solution: guard the load_oil_buffer() call in open_preview() with a check for vim.b[filebufnr].oil_ready. Buffers that are already initialized and rendered are not re-loaded, preserving any unsaved modifications the user has made. Closes: stevearc/oil.nvim#632 --- lua/oil/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/oil/init.lua b/lua/oil/init.lua index 7a70c15..0329afd 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -602,7 +602,7 @@ M.open_preview = function(opts, callback) -- If we called open_preview during an autocmd, then the edit command may not trigger the -- BufReadCmd to load the buffer. So we need to do it manually. - if util.is_oil_bufnr(filebufnr) then + if util.is_oil_bufnr(filebufnr) and not vim.b[filebufnr].oil_ready then M.load_oil_buffer(filebufnr) end