fix: set alternate buffer when inside oil (#60)

This commit is contained in:
Steven Arcangeli 2023-02-24 06:20:56 -08:00
parent 647c2d316c
commit f1131b5e90
2 changed files with 17 additions and 0 deletions

View file

@ -709,6 +709,12 @@ M.setup = function(opts)
local scheme = util.parse_url(bufname)
if scheme and config.adapters[scheme] then
require("oil.view").maybe_set_cursor()
-- While we are in an oil buffer, set the alternate file to the buffer we were in prior to
-- opening oil
local has_orig, orig_buffer = pcall(vim.api.nvim_win_get_var, 0, "oil_original_buffer")
if has_orig and vim.api.nvim_buf_is_valid(orig_buffer) then
vim.fn.setreg("#", orig_buffer)
end
elseif vim.fn.isdirectory(bufname) == 0 then
-- Only run this logic if we are *not* in an oil buffer (and it's not a directory, which
-- will be replaced by an oil:// url)

View file

@ -70,6 +70,17 @@ a.describe("Alternate buffer", function()
assert.equals("foo", vim.fn.expand("#"))
end)
a.it("sets previous buffer as alternate when inside oil buffer", function()
vim.cmd.edit({ args = { "foo" } })
oil.open()
test_util.wait_for_autocmd("BufReadPost")
assert.equals("foo", vim.fn.expand("#"))
vim.cmd.edit({ args = { "bar" } })
assert.equals("foo", vim.fn.expand("#"))
oil.open()
assert.equals("bar", vim.fn.expand("#"))
end)
a.describe("floating window", function()
a.it("sets previous buffer as alternate", function()
vim.cmd.edit({ args = { "foo" } })