Skip to content

Commit

Permalink
only use the previewwindow if requested by the user
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoKatel committed Dec 9, 2024
1 parent 9a59256 commit df7043a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lua/oil/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,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()

Expand Down Expand Up @@ -501,6 +501,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 })
Expand Down Expand Up @@ -568,6 +569,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
Expand Down
11 changes: 9 additions & 2 deletions lua/oil/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit df7043a

Please sign in to comment.