Skip to content

Commit

Permalink
fix: warning when :tabnew from oil buffer (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Jan 19, 2023
1 parent ca4da68 commit 73c6fcf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lua/oil/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,9 @@ M.setup = function(opts)
-- This new window is a split off of an oil window. We need to transfer the window
-- variables. First, locate the parent window
local parent_win
for _, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
-- First search windows in this tab, then search all windows
local winids = vim.list_extend(vim.api.nvim_tabpage_list_wins(0), vim.api.nvim_list_wins())
for _, winid in ipairs(winids) do
if vim.api.nvim_win_is_valid(winid) then
if vim.w[winid].oil_did_enter then
parent_win = winid
Expand Down
17 changes: 17 additions & 0 deletions tests/win_options_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,21 @@ a.describe("window options", function()
vim.cmd.edit({ args = { "README.md" } })
assert.equals("auto", vim.o.signcolumn)
end)

a.it("Restores window options on tabnew <filename>", function()
oil.open()
test_util.wait_for_autocmd("BufReadPost")
assert.equals("no", vim.o.signcolumn)
vim.cmd.tabnew({ args = { "README.md" } })
assert.equals("auto", vim.o.signcolumn)
end)

a.it("Restores window options on tabnew", function()
oil.open()
test_util.wait_for_autocmd("BufReadPost")
assert.equals("no", vim.o.signcolumn)
vim.cmd.tabnew()
vim.cmd.edit({ args = { "README.md" } })
assert.equals("auto", vim.o.signcolumn)
end)
end)

0 comments on commit 73c6fcf

Please sign in to comment.