fix: update preview window in-place (#74)
This commit is contained in:
parent
b8eaf88c12
commit
57451c517d
2 changed files with 27 additions and 19 deletions
|
|
@ -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,28 +414,34 @@ 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 vim.tbl_isempty(mods) then
|
if opts.preview and preview_win then
|
||||||
mods = nil
|
vim.api.nvim_set_current_win(preview_win)
|
||||||
end
|
vim.cmd.edit({ args = { url }, mods = mods })
|
||||||
local cmd
|
|
||||||
if opts.tab then
|
|
||||||
cmd = "tabedit"
|
|
||||||
elseif opts.split then
|
|
||||||
cmd = "split"
|
|
||||||
else
|
else
|
||||||
cmd = "edit"
|
if vim.tbl_isempty(mods) then
|
||||||
|
mods = nil
|
||||||
|
end
|
||||||
|
local cmd
|
||||||
|
if opts.tab then
|
||||||
|
cmd = "tabedit"
|
||||||
|
elseif opts.split then
|
||||||
|
cmd = "split"
|
||||||
|
else
|
||||||
|
cmd = "edit"
|
||||||
|
end
|
||||||
|
vim.cmd({
|
||||||
|
cmd = cmd,
|
||||||
|
args = { url },
|
||||||
|
mods = mods,
|
||||||
|
})
|
||||||
end
|
end
|
||||||
vim.cmd({
|
|
||||||
cmd = cmd,
|
|
||||||
args = { url },
|
|
||||||
mods = mods,
|
|
||||||
})
|
|
||||||
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)
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue