Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only use the previewwindow if requested by the user #532

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading