From 09eb34acdb71b872738ce9e11a57ab1d09ab040d Mon Sep 17 00:00:00 2001 From: Gustavo Sampaio Date: Sun, 8 Dec 2024 15:14:54 -0300 Subject: [PATCH] only use the previewwindow if requested by the user --- lua/oil/init.lua | 9 +++------ lua/oil/util.lua | 11 +++++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lua/oil/init.lua b/lua/oil/init.lua index 72d5538a..3e40d510 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -374,9 +374,6 @@ M.open = function(dir) if config.buf_options.buflisted ~= nil then vim.api.nvim_set_option_value("buflisted", config.buf_options.buflisted, { buf = 0 }) end - - -- If preview window exists, update its content - update_preview_window() end ---@class oil.CloseOpts @@ -454,7 +451,7 @@ M.open_preview = function(opts, callback) end end - local preview_win = util.get_preview_win() + local preview_win = util.get_preview_win({include_not_owned = true}) local prev_win = vim.api.nvim_get_current_win() local bufnr = vim.api.nvim_get_current_buf() @@ -501,6 +498,7 @@ M.open_preview = function(opts, callback) preview_win = vim.api.nvim_open_win(bufnr, true, win_opts) vim.api.nvim_set_option_value("previewwindow", true, { scope = "local", win = preview_win }) + vim.api.nvim_win_set_var(preview_win, "oil_preview", true) vim.api.nvim_set_current_win(prev_win) elseif vim.fn.has("nvim-0.9") == 1 then vim.api.nvim_win_set_config(preview_win, { title = entry_title }) @@ -568,6 +566,7 @@ M.open_preview = function(opts, callback) end vim.api.nvim_set_option_value("previewwindow", true, { scope = "local", win = 0 }) + vim.api.nvim_win_set_var(0, "oil_preview", true) for k, v in pairs(config.preview_win.win_options) do vim.api.nvim_set_option_value(k, v, { scope = "local", win = preview_win }) end @@ -764,8 +763,6 @@ M.select = function(opts, callback) end) end - update_preview_window() - finish() end) end diff --git a/lua/oil/util.lua b/lua/oil/util.lua index 441421b9..e209296a 100644 --- a/lua/oil/util.lua +++ b/lua/oil/util.lua @@ -668,10 +668,17 @@ M.hack_around_termopen_autocmd = function(prev_mode) end, 10) end +---@param opts {include_not_owned?: boolean} ---@return nil|integer -M.get_preview_win = function() +M.get_preview_win = function(opts) + opts = opts or {} + for _, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do - if vim.api.nvim_win_is_valid(winid) and vim.wo[winid].previewwindow then + if + vim.api.nvim_win_is_valid(winid) + and vim.wo[winid].previewwindow + and (opts.include_not_owned or vim.w[winid]["oil_preview"]) + then return winid end end