feat: config option to disable previewing a file
This commit is contained in:
parent
5acab3d8a9
commit
3fa3161aa9
4 changed files with 19 additions and 0 deletions
|
|
@ -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<string, any>
|
||||
|
||||
---@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<string, any> Window-local options to use for preview window buffers
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue