fix: update preview window in-place (#74)

This commit is contained in:
Steven Arcangeli 2023-03-18 15:08:32 -07:00
parent b8eaf88c12
commit 57451c517d
2 changed files with 27 additions and 19 deletions

View file

@ -382,11 +382,10 @@ M.select = function(opts)
vim.notify("Cannot preview multiple entries", vim.log.levels.WARN) vim.notify("Cannot preview multiple entries", vim.log.levels.WARN)
entries = { entries[1] } entries = { entries[1] }
end end
-- Close the preview window -- Close the preview window if we're not previewing the selection
for _, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do local preview_win = util.get_preview_win()
if vim.api.nvim_win_is_valid(winid) and vim.api.nvim_win_get_option(winid, "previewwindow") then if not opts.preview and preview_win then
vim.api.nvim_win_close(winid, true) vim.api.nvim_win_close(preview_win, true)
end
end end
local bufname = vim.api.nvim_buf_get_name(0) local bufname = vim.api.nvim_buf_get_name(0)
local prev_win = vim.api.nvim_get_current_win() local prev_win = vim.api.nvim_get_current_win()
@ -415,12 +414,17 @@ M.select = function(opts)
vim.api.nvim_win_close(0, false) vim.api.nvim_win_close(0, false)
end end
end end
local mods = { local mods = {
vertical = opts.vertical, vertical = opts.vertical,
horizontal = opts.horizontal, horizontal = opts.horizontal,
split = opts.split, split = opts.split,
keepalt = true, keepalt = true,
} }
if opts.preview and preview_win then
vim.api.nvim_set_current_win(preview_win)
vim.cmd.edit({ args = { url }, mods = mods })
else
if vim.tbl_isempty(mods) then if vim.tbl_isempty(mods) then
mods = nil mods = nil
end end
@ -437,6 +441,7 @@ M.select = function(opts)
args = { url }, args = { url },
mods = mods, mods = mods,
}) })
end
if opts.preview then if opts.preview then
vim.api.nvim_win_set_option(0, "previewwindow", true) vim.api.nvim_win_set_option(0, "previewwindow", true)
vim.api.nvim_win_set_var(0, "oil_entry_id", entry.id) vim.api.nvim_win_set_var(0, "oil_entry_id", entry.id)

View file

@ -254,6 +254,9 @@ M.initialize = function(bufnr)
callback = function() callback = function()
local oil = require("oil") local oil = require("oil")
local parser = require("oil.mutator.parser") local parser = require("oil.mutator.parser")
if vim.wo.previewwindow then
return
end
-- Force the cursor to be after the (concealed) ID at the beginning of the line -- Force the cursor to be after the (concealed) ID at the beginning of the line
local adapter = util.get_adapter(bufnr) local adapter = util.get_adapter(bufnr)