Skip to content

Commit

Permalink
fix: oil loses track of buffers after refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Mar 30, 2023
1 parent 092f4b1 commit 9871ca9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lua/oil/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ M.initialize = function(bufnr)
if not vim.api.nvim_buf_is_valid(bufnr) then
return
end
vim.api.nvim_clear_autocmds({
buffer = bufnr,
group = "Oil",
})
vim.bo[bufnr].buftype = "acwrite"
vim.bo[bufnr].syntax = "oil"
vim.bo[bufnr].filetype = "oil"
Expand All @@ -231,10 +235,6 @@ M.initialize = function(bufnr)
vim.api.nvim_buf_set_option(bufnr, k, v)
end
M.set_win_options()
vim.api.nvim_clear_autocmds({
buffer = bufnr,
group = "Oil",
})
vim.api.nvim_create_autocmd("BufHidden", {
desc = "Delete oil buffers when no longer in use",
group = "Oil",
Expand Down
9 changes: 9 additions & 0 deletions tests/regression_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,13 @@ a.describe("regression tests", function()
-- The first oil buffer should not be modified anymore
assert.falsy(vim.bo[first_dir].modified)
end)

a.it("refreshing buffer doesn't lose track of it", function()
vim.cmd.edit({ args = { "." } })
test_util.wait_for_autocmd("BufReadPost")
local bufnr = vim.api.nvim_get_current_buf()
vim.cmd.edit({ bang = true })
test_util.wait_for_autocmd("BufReadPost")
assert.are.same({ bufnr }, require("oil.view").get_all_buffers())
end)
end)

0 comments on commit 9871ca9

Please sign in to comment.