fix: another case of incorrect alternate buffers (#60)
This commit is contained in:
parent
4152810907
commit
b36ba91b7a
3 changed files with 30 additions and 0 deletions
|
|
@ -405,6 +405,7 @@ M.select = function(opts)
|
||||||
vertical = opts.vertical,
|
vertical = opts.vertical,
|
||||||
horizontal = opts.horizontal,
|
horizontal = opts.horizontal,
|
||||||
split = opts.split,
|
split = opts.split,
|
||||||
|
keepalt = true,
|
||||||
}
|
}
|
||||||
if vim.tbl_isempty(mods) then
|
if vim.tbl_isempty(mods) then
|
||||||
mods = nil
|
mods = nil
|
||||||
|
|
|
||||||
|
|
@ -102,11 +102,16 @@ M.rename_buffer = function(src_bufnr, dest_buf_name)
|
||||||
-- rename logic. The only reason we can't use nvim_buf_set_name on files is because vim will
|
-- rename logic. The only reason we can't use nvim_buf_set_name on files is because vim will
|
||||||
-- think that the new buffer conflicts with the file next time it tries to save.
|
-- think that the new buffer conflicts with the file next time it tries to save.
|
||||||
if not vim.loop.fs_stat(dest_buf_name) then
|
if not vim.loop.fs_stat(dest_buf_name) then
|
||||||
|
local altbuf = vim.fn.bufnr("#")
|
||||||
-- This will fail if the dest buf name already exists
|
-- This will fail if the dest buf name already exists
|
||||||
local ok = pcall(vim.api.nvim_buf_set_name, src_bufnr, dest_buf_name)
|
local ok = pcall(vim.api.nvim_buf_set_name, src_bufnr, dest_buf_name)
|
||||||
if ok then
|
if ok then
|
||||||
-- Renaming the buffer creates a new buffer with the old name. Find it and delete it.
|
-- Renaming the buffer creates a new buffer with the old name. Find it and delete it.
|
||||||
vim.api.nvim_buf_delete(vim.fn.bufadd(bufname), {})
|
vim.api.nvim_buf_delete(vim.fn.bufadd(bufname), {})
|
||||||
|
if altbuf and vim.api.nvim_buf_is_valid(altbuf) then
|
||||||
|
vim.fn.setreg("#", altbuf)
|
||||||
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,30 @@ a.describe("Alternate buffer", function()
|
||||||
assert.equals("bar", vim.fn.expand("#"))
|
assert.equals("bar", vim.fn.expand("#"))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
a.it("preserves alternate when traversing oil dirs", function()
|
||||||
|
vim.cmd.edit({ args = { "foo" } })
|
||||||
|
oil.open()
|
||||||
|
test_util.wait_for_autocmd("BufReadPost")
|
||||||
|
a.util.sleep(10)
|
||||||
|
assert.equals("foo", vim.fn.expand("#"))
|
||||||
|
vim.api.nvim_win_set_cursor(0, { 1, 1 })
|
||||||
|
oil.select()
|
||||||
|
test_util.wait_for_autocmd("BufReadPost")
|
||||||
|
assert.equals("foo", vim.fn.expand("#"))
|
||||||
|
end)
|
||||||
|
|
||||||
|
a.it("preserves alternate when opening preview", function()
|
||||||
|
vim.cmd.edit({ args = { "foo" } })
|
||||||
|
oil.open()
|
||||||
|
test_util.wait_for_autocmd("BufReadPost")
|
||||||
|
a.util.sleep(10)
|
||||||
|
assert.equals("foo", vim.fn.expand("#"))
|
||||||
|
vim.api.nvim_win_set_cursor(0, { 1, 1 })
|
||||||
|
oil.select({ preview = true })
|
||||||
|
test_util.wait_for_autocmd("BufReadPost")
|
||||||
|
assert.equals("foo", vim.fn.expand("#"))
|
||||||
|
end)
|
||||||
|
|
||||||
a.describe("floating window", function()
|
a.describe("floating window", function()
|
||||||
a.it("sets previous buffer as alternate", function()
|
a.it("sets previous buffer as alternate", function()
|
||||||
vim.cmd.edit({ args = { "foo" } })
|
vim.cmd.edit({ args = { "foo" } })
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue