feat: add 'update_on_cursor_moved' option to preview window (#250)
This commit is contained in:
parent
a173b5776c
commit
ea612fe926
3 changed files with 31 additions and 25 deletions
|
|
@ -120,6 +120,8 @@ local default_config = {
|
|||
win_options = {
|
||||
winblend = 0,
|
||||
},
|
||||
-- Whether the preview window is automatically updated when the cursor is moved
|
||||
update_on_cursor_moved = true,
|
||||
},
|
||||
-- Configuration for the floating progress window
|
||||
progress = {
|
||||
|
|
|
|||
|
|
@ -364,34 +364,36 @@ M.initialize = function(bufnr)
|
|||
end
|
||||
end
|
||||
|
||||
-- Debounce and update the preview window
|
||||
if timer then
|
||||
timer:again()
|
||||
return
|
||||
end
|
||||
timer = vim.loop.new_timer()
|
||||
if not timer then
|
||||
return
|
||||
end
|
||||
timer:start(10, 100, function()
|
||||
timer:stop()
|
||||
timer:close()
|
||||
timer = nil
|
||||
vim.schedule(function()
|
||||
if vim.api.nvim_get_current_buf() ~= bufnr then
|
||||
return
|
||||
end
|
||||
local entry = oil.get_cursor_entry()
|
||||
if entry then
|
||||
local winid = util.get_preview_win()
|
||||
if winid then
|
||||
if entry.id ~= vim.w[winid].oil_entry_id then
|
||||
oil.select({ preview = true })
|
||||
if config.preview.update_on_cursor_moved then
|
||||
-- Debounce and update the preview window
|
||||
if timer then
|
||||
timer:again()
|
||||
return
|
||||
end
|
||||
timer = vim.loop.new_timer()
|
||||
if not timer then
|
||||
return
|
||||
end
|
||||
timer:start(10, 100, function()
|
||||
timer:stop()
|
||||
timer:close()
|
||||
timer = nil
|
||||
vim.schedule(function()
|
||||
if vim.api.nvim_get_current_buf() ~= bufnr then
|
||||
return
|
||||
end
|
||||
local entry = oil.get_cursor_entry()
|
||||
if entry then
|
||||
local winid = util.get_preview_win()
|
||||
if winid then
|
||||
if entry.id ~= vim.w[winid].oil_entry_id then
|
||||
oil.select({ preview = true })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue