Skip to content

Commit

Permalink
feat: disable preview for large files
Browse files Browse the repository at this point in the history
  • Loading branch information
stevalkr committed Nov 11, 2024
1 parent 50c4bd4 commit 1aad2d6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ require("oil").setup({
preview_win = {
-- Whether the preview window is automatically updated when the cursor is moved
update_on_cursor_moved = true,
-- Maximum file size in megabytes to preview
max_file_size = 100,
},
-- Configuration for the floating action confirmation window
confirmation = {
Expand Down
2 changes: 2 additions & 0 deletions doc/oil.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ CONFIG *oil-confi
preview_win = {
-- Whether the preview window is automatically updated when the cursor is moved
update_on_cursor_moved = true,
-- Maximum file size in megabytes to preview
max_file_size = 100,
},
-- Configuration for the floating action confirmation window
confirmation = {
Expand Down
3 changes: 3 additions & 0 deletions lua/oil/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ local default_config = {
preview_win = {
-- Whether the preview window is automatically updated when the cursor is moved
update_on_cursor_moved = true,
-- Maximum file size in megabytes to preview
max_file_size = 100,
},
-- Configuration for the floating action confirmation window
confirmation = {
Expand Down Expand Up @@ -328,6 +330,7 @@ local M = {}

---@class (exact) oil.SetupPreviewWindowConfig
---@field update_on_cursor_moved? boolean Whether the preview window is automatically updated when the cursor is moved
---@field max_file_size? number Maximum file size in megabytes to preview

---@class (exact) oil.SetupConfirmationWindowConfig : oil.SetupWindowConfig

Expand Down
5 changes: 5 additions & 0 deletions lua/oil/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,11 @@ M.open_preview = function(opts, callback)
if not entry then
return finish("Could not find entry under cursor")
end
if entry.meta ~= nil or entry.meta.stat ~= nil then
if entry.meta.stat.size >= config.preview.max_file_size * 1e6 then
return finish("File over " .. config.preview.max_file_size .. "MB is too large to preview ")
end
end
local entry_title = entry.name
if entry.type == "directory" then
entry_title = entry_title .. "/"
Expand Down

0 comments on commit 1aad2d6

Please sign in to comment.