Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable preview for large files #511

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_mb = 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_mb = 100,
},
-- Configuration for the floating action confirmation window
confirmation = {
Expand Down
4 changes: 4 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_mb = 100,
},
-- Configuration for the floating action confirmation window
confirmation = {
Expand Down Expand Up @@ -323,11 +325,13 @@ local M = {}

---@class (exact) oil.PreviewWindowConfig
---@field update_on_cursor_moved boolean
---@field max_file_size_mb number

---@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 max_file_size_mb? number Maximum file size in megabytes to preview

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

Expand Down
7 changes: 7 additions & 0 deletions lua/oil/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,13 @@ M.open_preview = function(opts, callback)
if not entry then
return finish("Could not find entry under cursor")
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
if entry.type == "directory" then
entry_title = entry_title .. "/"
Expand Down