fix: don't close floating windows we didn't open (#64)

This commit is contained in:
Steven Arcangeli 2023-03-04 22:24:39 -08:00
parent 0b2a4ddde1
commit 073ecb3d68
2 changed files with 20 additions and 4 deletions

View file

@ -254,6 +254,7 @@ M.open_float = function(dir)
border = config.float.border,
zindex = 45,
})
vim.w[winid].is_oil_win = true
local winleave_autocmd
winleave_autocmd = vim.api.nvim_create_autocmd("WinLeave", {
desc = "Close floating oil window",
@ -292,8 +293,7 @@ end
---Restore the buffer that was present when oil was opened
M.close = function()
local util = require("oil.util")
if util.is_floating_win(0) then
if vim.w.is_oil_win then
vim.api.nvim_win_close(0, true)
return
end
@ -308,7 +308,7 @@ M.close = function()
end
---Select the entry under the cursor
---@param opts table
---@param opts nil|table
--- vertical boolean Open the buffer in a vertical split
--- horizontal boolean Open the buffer in a horizontal split
--- split "aboveleft"|"belowright"|"topleft"|"botright" Split modifier
@ -397,7 +397,7 @@ M.select = function(opts)
return
end
else
if util.is_floating_win() then
if vim.w.is_oil_win then
vim.api.nvim_win_close(0, false)
end
end

View file

@ -31,4 +31,20 @@ a.describe("regression tests", function()
entry = oil.get_cursor_entry()
assert.equals("README.md", entry and entry.name)
end)
-- https://github.com/stevearc/oil.nvim/issues/64
a.it("doesn't close floating windows oil didn't open itself", function()
local winid = vim.api.nvim_open_win(vim.fn.bufadd("README.md"), true, {
relative = "editor",
row = 1,
col = 1,
width = 100,
height = 100,
})
oil.open()
a.util.sleep(10)
oil.close()
a.util.sleep(10)
assert.equals(winid, vim.api.nvim_get_current_win())
end)
end)