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
|
|
@ -134,6 +134,8 @@ OPTIONS *oil-option
|
||||||
win_options = {
|
win_options = {
|
||||||
winblend = 0,
|
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
|
-- Configuration for the floating progress window
|
||||||
progress = {
|
progress = {
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,8 @@ local default_config = {
|
||||||
win_options = {
|
win_options = {
|
||||||
winblend = 0,
|
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
|
-- Configuration for the floating progress window
|
||||||
progress = {
|
progress = {
|
||||||
|
|
|
||||||
|
|
@ -364,34 +364,36 @@ M.initialize = function(bufnr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Debounce and update the preview window
|
if config.preview.update_on_cursor_moved then
|
||||||
if timer then
|
-- Debounce and update the preview window
|
||||||
timer:again()
|
if timer then
|
||||||
return
|
timer:again()
|
||||||
end
|
return
|
||||||
timer = vim.loop.new_timer()
|
end
|
||||||
if not timer then
|
timer = vim.loop.new_timer()
|
||||||
return
|
if not timer then
|
||||||
end
|
return
|
||||||
timer:start(10, 100, function()
|
end
|
||||||
timer:stop()
|
timer:start(10, 100, function()
|
||||||
timer:close()
|
timer:stop()
|
||||||
timer = nil
|
timer:close()
|
||||||
vim.schedule(function()
|
timer = nil
|
||||||
if vim.api.nvim_get_current_buf() ~= bufnr then
|
vim.schedule(function()
|
||||||
return
|
if vim.api.nvim_get_current_buf() ~= bufnr then
|
||||||
end
|
return
|
||||||
local entry = oil.get_cursor_entry()
|
end
|
||||||
if entry then
|
local entry = oil.get_cursor_entry()
|
||||||
local winid = util.get_preview_win()
|
if entry then
|
||||||
if winid then
|
local winid = util.get_preview_win()
|
||||||
if entry.id ~= vim.w[winid].oil_entry_id then
|
if winid then
|
||||||
oil.select({ preview = true })
|
if entry.id ~= vim.w[winid].oil_entry_id then
|
||||||
|
oil.select({ preview = true })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue