From ea612fe926a24ea20b2b3856e1ba60bdaaae9383 Mon Sep 17 00:00:00 2001 From: umlx5h Date: Sun, 10 Dec 2023 12:02:04 +0900 Subject: [PATCH] feat: add 'update_on_cursor_moved' option to preview window (#250) --- doc/oil.txt | 2 ++ lua/oil/config.lua | 2 ++ lua/oil/view.lua | 52 ++++++++++++++++++++++++---------------------- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/doc/oil.txt b/doc/oil.txt index 4b4b5cda..91f478b8 100644 --- a/doc/oil.txt +++ b/doc/oil.txt @@ -134,6 +134,8 @@ OPTIONS *oil-option 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 = { diff --git a/lua/oil/config.lua b/lua/oil/config.lua index 0e419d26..789df88f 100644 --- a/lua/oil/config.lua +++ b/lua/oil/config.lua @@ -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 = { diff --git a/lua/oil/view.lua b/lua/oil/view.lua index e2a05f97..5419571b 100644 --- a/lua/oil/view.lua +++ b/lua/oil/view.lua @@ -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, })