From c5f7c56644425e2b77e71904da98cda0331b3342 Mon Sep 17 00:00:00 2001 From: David Marchante <6660202+iovis@users.noreply.github.com> Date: Fri, 20 Dec 2024 23:18:49 -0500 Subject: [PATCH] fix: set alternate when using floating windows (#526) --- lua/oil/init.lua | 2 +- tests/altbuf_spec.lua | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lua/oil/init.lua b/lua/oil/init.lua index 275c97d..5471bb0 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -720,7 +720,7 @@ M.select = function(opts, callback) vertical = opts.vertical, horizontal = opts.horizontal, split = opts.split, - keepalt = true, + keepalt = false, } local filebufnr = vim.fn.bufadd(normalized_url) local entry_is_file = not vim.endswith(normalized_url, "/") diff --git a/tests/altbuf_spec.lua b/tests/altbuf_spec.lua index 4b51604..beece15 100644 --- a/tests/altbuf_spec.lua +++ b/tests/altbuf_spec.lua @@ -141,5 +141,17 @@ a.describe("Alternate buffer", function() oil.close() assert.equals("foo", vim.fn.expand("#")) end) + + a.it("preserves alternate when traversing to a new file", function() + vim.cmd.edit({ args = { "foo" } }) + oil.open_float() + test_util.wait_for_autocmd({ "User", pattern = "OilEnter" }) + assert.equals("foo", vim.fn.expand("#")) + test_util.feedkeys({ "/LICENSE" }, 10) + oil.select() + test_util.wait_for_autocmd("BufEnter") + assert.equals("LICENSE", vim.fn.expand("%:.")) + assert.equals("foo", vim.fn.expand("#")) + end) end) end)