Skip to content

fix: load directory buffers created with bufadd() after setup - #795

Open
MaxWang007 wants to merge 1 commit into
stevearc:masterfrom
MaxWang007:cursor/fix-bufadd-directory-hijack-8312
Open

MaxWang007 wants to merge 1 commit into
stevearc:masterfrom
MaxWang007:cursor/fix-bufadd-directory-hijack-8312

Conversation

@MaxWang007

Copy link
Copy Markdown

Fixes #782

vim.fn.bufadd() creates an unlisted buffer, so only BufNew fires, not BufAdd. Oil only hijacked directories on BufAdd, which left nvim_set_current_buf() showing a blank directory buffer.

If that already-loaded buffer was later listed, it got renamed to oil://… but BufReadCmd did not run, so the listing stayed empty. That's the same gap SessionLoadPost already covers with load_oil_buffer().

This change hijacks unlisted directory buffers created after setup(), and calls load_oil_buffer() when a hijacked buffer is already loaded. Directory buffers that existed before setup() are left to #792.

./run_tests.sh on Neovim v0.12.6: 110 passed, including 2 new regressions that fail on current master. StyLua and luacheck passed on the touched files. AI was used to help implement this.

bufadd() does not list the buffer, so Oil's BufAdd autocmd never runs
and nvim_set_current_buf() shows a blank directory. Listing that loaded
buffer later renames it to oil:// without reading it. Hijack unlisted
directory buffers created after setup, and load a directory buffer that
is already loaded when it is hijacked.

Fixes stevearc#782

Co-authored-by: MaxWang007 <MaxWang007@users.noreply.github.com>
@github-actions
github-actions Bot requested a review from stevearc November 16, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: bufadd() on a directory bypasses the default_file_explorer hijack

1 participant