fix: oil.close doesn't error when no other buffers exist (#79)
This commit is contained in:
parent
08c4b71ef1
commit
4b05ebdf20
2 changed files with 14 additions and 1 deletions
|
|
@ -317,7 +317,11 @@ M.close = function()
|
|||
-- Deleting the buffer closes all windows with that buffer open, so navigate to a different
|
||||
-- buffer first
|
||||
local oilbuf = vim.api.nvim_get_current_buf()
|
||||
vim.cmd.bprev()
|
||||
ok = pcall(vim.cmd.bprev)
|
||||
if not ok then
|
||||
-- If `bprev` failed, there are no buffers open so we should create a new one with enew
|
||||
vim.cmd.enew()
|
||||
end
|
||||
vim.api.nvim_buf_delete(oilbuf, { force = true })
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -62,4 +62,13 @@ a.describe("regression tests", function()
|
|||
assert.equals(winid, vim.api.nvim_get_current_win())
|
||||
assert.equals(bufnr, vim.api.nvim_get_current_buf())
|
||||
end)
|
||||
|
||||
-- https://github.com/stevearc/oil.nvim/issues/79
|
||||
a.it("Returns to empty buffer on close", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
oil.close()
|
||||
assert.not_equals("oil", vim.bo.filetype)
|
||||
assert.equals("", vim.api.nvim_buf_get_name(0))
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue