feat: disable preview for large files (#511)
* feat: disable preview for large files fix: update oil.PreviewWindowConfig * refactor: remove unnecessary shim in config.lua * refactor: revert changes to shim --------- Co-authored-by: Steve Walker <65963536+etherswangel@users.noreply.github.com> Co-authored-by: Steven Arcangeli <506791+stevearc@users.noreply.github.com>
This commit is contained in:
parent
50c4bd4ee2
commit
c23fe08e05
4 changed files with 15 additions and 0 deletions
|
|
@ -271,6 +271,8 @@ require("oil").setup({
|
||||||
preview_win = {
|
preview_win = {
|
||||||
-- Whether the preview window is automatically updated when the cursor is moved
|
-- Whether the preview window is automatically updated when the cursor is moved
|
||||||
update_on_cursor_moved = true,
|
update_on_cursor_moved = true,
|
||||||
|
-- Maximum file size in megabytes to preview
|
||||||
|
max_file_size_mb = 100,
|
||||||
},
|
},
|
||||||
-- Configuration for the floating action confirmation window
|
-- Configuration for the floating action confirmation window
|
||||||
confirmation = {
|
confirmation = {
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,8 @@ CONFIG *oil-confi
|
||||||
preview_win = {
|
preview_win = {
|
||||||
-- Whether the preview window is automatically updated when the cursor is moved
|
-- Whether the preview window is automatically updated when the cursor is moved
|
||||||
update_on_cursor_moved = true,
|
update_on_cursor_moved = true,
|
||||||
|
-- Maximum file size in megabytes to preview
|
||||||
|
max_file_size_mb = 100,
|
||||||
},
|
},
|
||||||
-- Configuration for the floating action confirmation window
|
-- Configuration for the floating action confirmation window
|
||||||
confirmation = {
|
confirmation = {
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,8 @@ local default_config = {
|
||||||
preview_win = {
|
preview_win = {
|
||||||
-- Whether the preview window is automatically updated when the cursor is moved
|
-- Whether the preview window is automatically updated when the cursor is moved
|
||||||
update_on_cursor_moved = true,
|
update_on_cursor_moved = true,
|
||||||
|
-- Maximum file size in megabytes to preview
|
||||||
|
max_file_size_mb = 100,
|
||||||
},
|
},
|
||||||
-- Configuration for the floating action confirmation window
|
-- Configuration for the floating action confirmation window
|
||||||
confirmation = {
|
confirmation = {
|
||||||
|
|
@ -323,11 +325,13 @@ local M = {}
|
||||||
|
|
||||||
---@class (exact) oil.PreviewWindowConfig
|
---@class (exact) oil.PreviewWindowConfig
|
||||||
---@field update_on_cursor_moved boolean
|
---@field update_on_cursor_moved boolean
|
||||||
|
---@field max_file_size_mb number
|
||||||
|
|
||||||
---@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 max_file_size_mb? number Maximum file size in megabytes to preview
|
||||||
|
|
||||||
---@class (exact) oil.SetupConfirmationWindowConfig : oil.SetupWindowConfig
|
---@class (exact) oil.SetupConfirmationWindowConfig : oil.SetupWindowConfig
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -452,6 +452,13 @@ M.open_preview = function(opts, callback)
|
||||||
if not entry then
|
if not entry then
|
||||||
return finish("Could not find entry under cursor")
|
return finish("Could not find entry under cursor")
|
||||||
end
|
end
|
||||||
|
if entry.meta ~= nil and entry.meta.stat ~= nil then
|
||||||
|
if entry.meta.stat.size >= config.preview_win.max_file_size_mb * 1e6 then
|
||||||
|
return finish(
|
||||||
|
"File over " .. config.preview_win.max_file_size_mb .. "MB is too large to preview"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
local entry_title = entry.name
|
local entry_title = entry.name
|
||||||
if entry.type == "directory" then
|
if entry.type == "directory" then
|
||||||
entry_title = entry_title .. "/"
|
entry_title = entry_title .. "/"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue