fix: preserve alternate buffer when using floating window (#20)

This commit is contained in:
Steven Arcangeli 2023-01-08 22:12:17 -08:00
parent e4c4110022
commit d8a1e7ca4e
2 changed files with 34 additions and 1 deletions

View file

@ -388,8 +388,10 @@ M.select = function(opts)
vertical = opts.vertical,
horizontal = opts.horizontal,
split = opts.split,
keepalt = true,
}
if vim.tbl_isempty(mods) then
mods = nil
end
local cmd = opts.split and "split" or "edit"
vim.cmd({
cmd = cmd,

View file

@ -46,4 +46,35 @@ describe("Alternate buffer", function()
vim.cmd.edit({ args = { "bar" } })
assert.equals("foo", vim.fn.expand("#"))
end)
describe("floating window", function()
it("sets previous buffer as alternate", function()
vim.cmd.edit({ args = { "foo" } })
oil.open_float()
-- This is lazy, but testing the actual select logic is more difficult. We can simply
-- replicated it by closing the current window and then doing the edit
vim.api.nvim_win_close(0, true)
vim.cmd.edit({ args = { "bar" } })
assert.equals("foo", vim.fn.expand("#"))
end)
it("preserves alternate buffer if editing the same file", function()
vim.cmd.edit({ args = { "foo" } })
vim.cmd.edit({ args = { "bar" } })
oil.open_float()
-- This is lazy, but testing the actual select logic is more difficult. We can simply
-- replicated it by closing the current window and then doing the edit
vim.api.nvim_win_close(0, true)
vim.cmd.edit({ args = { "bar" } })
assert.equals("foo", vim.fn.expand("#"))
end)
it("preserves alternate buffer if discarding changes", function()
vim.cmd.edit({ args = { "foo" } })
vim.cmd.edit({ args = { "bar" } })
oil.open_float()
oil.close()
assert.equals("foo", vim.fn.expand("#"))
end)
end)
end)