From b8eaf88c127b7807fa3a8b00be881ab94f5168b3 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Sat, 18 Mar 2023 15:05:59 -0700 Subject: [PATCH] fix: edge case where window options were not set --- lua/oil/init.lua | 4 ++++ tests/win_options_spec.lua | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lua/oil/init.lua b/lua/oil/init.lua index 22d8547..bf4d26a 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -742,6 +742,10 @@ M.setup = function(opts) if has_orig and vim.api.nvim_buf_is_valid(orig_buffer) then vim.fn.setreg("#", orig_buffer) end + if not vim.w.oil_did_enter then + require("oil.view").set_win_options() + vim.w.oil_did_enter = true + end elseif vim.fn.isdirectory(bufname) == 0 then -- Only run this logic if we are *not* in an oil buffer (and it's not a directory, which -- will be replaced by an oil:// url) diff --git a/tests/win_options_spec.lua b/tests/win_options_spec.lua index 05f84d0..49ab811 100644 --- a/tests/win_options_spec.lua +++ b/tests/win_options_spec.lua @@ -57,4 +57,16 @@ a.describe("window options", function() vim.cmd.edit({ args = { "README.md" } }) assert.equals("auto", vim.o.signcolumn) end) + + a.it("Sets the window options when re-entering oil buffer", function() + oil.open() + test_util.wait_for_autocmd("BufReadPost") + assert.truthy(vim.w.oil_did_enter) + vim.cmd.edit({ args = { "README.md" } }) + assert.falsy(vim.w.oil_did_enter) + oil.open() + assert.truthy(vim.w.oil_did_enter) + vim.cmd.vsplit() + assert.truthy(vim.w.oil_did_enter) + end) end)