fix: preserve alternate buffer when using floating window (#20)
This commit is contained in:
parent
e4c4110022
commit
d8a1e7ca4e
2 changed files with 34 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue