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
|
|
@ -274,6 +274,10 @@ require("oil").setup({
|
||||||
update_on_cursor_moved = true,
|
update_on_cursor_moved = true,
|
||||||
-- How to open the preview window "load"|"scratch"|"fast_scratch"
|
-- How to open the preview window "load"|"scratch"|"fast_scratch"
|
||||||
preview_method = "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
|
-- Window-local options to use for preview window buffers
|
||||||
win_options = {},
|
win_options = {},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,10 @@ CONFIG *oil-confi
|
||||||
update_on_cursor_moved = true,
|
update_on_cursor_moved = true,
|
||||||
-- How to open the preview window "load"|"scratch"|"fast_scratch"
|
-- How to open the preview window "load"|"scratch"|"fast_scratch"
|
||||||
preview_method = "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
|
-- Window-local options to use for preview window buffers
|
||||||
win_options = {},
|
win_options = {},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,10 @@ local default_config = {
|
||||||
update_on_cursor_moved = true,
|
update_on_cursor_moved = true,
|
||||||
-- How to open the preview window "load"|"scratch"|"fast_scratch"
|
-- How to open the preview window "load"|"scratch"|"fast_scratch"
|
||||||
preview_method = "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
|
-- Window-local options to use for preview window buffers
|
||||||
win_options = {},
|
win_options = {},
|
||||||
},
|
},
|
||||||
|
|
@ -334,12 +338,14 @@ local M = {}
|
||||||
---@class (exact) oil.PreviewWindowConfig
|
---@class (exact) oil.PreviewWindowConfig
|
||||||
---@field update_on_cursor_moved boolean
|
---@field update_on_cursor_moved boolean
|
||||||
---@field preview_method oil.PreviewMethod
|
---@field preview_method oil.PreviewMethod
|
||||||
|
---@field disable_preview fun(filename: string): boolean
|
||||||
---@field win_options table<string, any>
|
---@field win_options table<string, any>
|
||||||
|
|
||||||
---@class (exact) oil.ConfirmationWindowConfig : oil.WindowConfig
|
---@class (exact) oil.ConfirmationWindowConfig : oil.WindowConfig
|
||||||
|
|
||||||
---@class (exact) oil.SetupPreviewWindowConfig
|
---@class (exact) oil.SetupPreviewWindowConfig
|
||||||
---@field update_on_cursor_moved? boolean Whether the preview window is automatically updated when the cursor is moved
|
---@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 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
|
---@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
|
then
|
||||||
filebufnr =
|
filebufnr =
|
||||||
util.read_file_to_scratch_buffer(normalized_url, config.preview_win.preview_method)
|
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
|
end
|
||||||
|
|
||||||
if not filebufnr then
|
if not filebufnr then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue