Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
f42c9dabd9
fix(preview): prevent preview from re-initializing modified oil buffers
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
2026-02-21 02:42:51 -05:00

View file

@ -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