diff --git a/README.md b/README.md index e249c39..684ff24 100644 --- a/README.md +++ b/README.md @@ -274,6 +274,10 @@ require("oil").setup({ update_on_cursor_moved = true, -- How to open the preview window "load"|"scratch"|"fast_scratch" preview_method = "fast_scratch", + -- A function that returns true to disable preview on a file e.g. to avoid lag + disable_preview = function(filename) + return false + end, -- Window-local options to use for preview window buffers win_options = {}, }, diff --git a/doc/oil.txt b/doc/oil.txt index 1ee0d11..0cfb872 100644 --- a/doc/oil.txt +++ b/doc/oil.txt @@ -159,6 +159,10 @@ CONFIG *oil-confi update_on_cursor_moved = true, -- How to open the preview window "load"|"scratch"|"fast_scratch" preview_method = "fast_scratch", + -- A function that returns true to disable preview on a file e.g. to avoid lag + disable_preview = function(filename) + return false + end, -- Window-local options to use for preview window buffers win_options = {}, }, diff --git a/lua/oil/config.lua b/lua/oil/config.lua index 3b6b57e..185cb15 100644 --- a/lua/oil/config.lua +++ b/lua/oil/config.lua @@ -144,6 +144,10 @@ local default_config = { update_on_cursor_moved = true, -- How to open the preview window "load"|"scratch"|"fast_scratch" preview_method = "fast_scratch", + -- A function that returns true to disable preview on a file e.g. to avoid lag + disable_preview = function(filename) + return false + end, -- Window-local options to use for preview window buffers win_options = {}, }, @@ -334,12 +338,14 @@ local M = {} ---@class (exact) oil.PreviewWindowConfig ---@field update_on_cursor_moved boolean ---@field preview_method oil.PreviewMethod +---@field disable_preview fun(filename: string): boolean ---@field win_options table ---@class (exact) oil.ConfirmationWindowConfig : oil.WindowConfig ---@class (exact) oil.SetupPreviewWindowConfig ---@field update_on_cursor_moved? boolean Whether the preview window is automatically updated when the cursor is moved +---@field disable_preview? fun(filename: string): boolean A function that returns true to disable preview on a file e.g. to avoid lag ---@field preview_method? oil.PreviewMethod How to open the preview window ---@field win_options? table Window-local options to use for preview window buffers diff --git a/lua/oil/init.lua b/lua/oil/init.lua index bbd290d..1450646 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -541,6 +541,11 @@ M.open_preview = function(opts, callback) then filebufnr = util.read_file_to_scratch_buffer(normalized_url, config.preview_win.preview_method) + elseif entry_is_file and config.preview_win.disable_preview(normalized_url) then + filebufnr = vim.api.nvim_create_buf(false, true) + vim.bo[filebufnr].bufhidden = "wipe" + vim.bo[filebufnr].buftype = "nofile" + util.render_text(filebufnr, "Preview disabled", { winid = preview_win }) end if not filebufnr then