feat: add max_file_size preview limit and show_hidden_when_empty (#85)

* feat(preview): add `max_file_size` config to skip large file previews

Problem: previewing large files (e.g. 500 MB logs, binaries) loads them
into a buffer and can freeze or OOM Neovim. `disable_preview` only
receives the filename, so users cannot gate on file size.

Solution: add `preview_win.max_file_size` (number, MB, default 10). In
`open_preview`, check `entry.meta.stat.size` and fall back to
`vim.uv.fs_stat` when the cached stat is absent. If the file exceeds
the limit and a preview window is already open, render "File too large
to preview" in it; if not, emit a WARN notify and return early. The
cursor-moved auto-update path only fires when a window already exists,
so no flag threading is needed to distinguish explicit from implicit.

Based on: stevearc/oil.nvim#213

* feat(view): add `show_hidden_when_empty` for hidden-only directories

Problem: with `show_hidden = false`, a directory containing only
dotfiles renders as just `..`, giving no indication that entries exist.

Solution: add `view_options.show_hidden_when_empty` (boolean, default
false). After the main filter loop in `render_buffer`, if the option is
set and `#line_table <= 1`, iterate `entry_list` again and render any
entry not matched by `is_always_hidden`, using `is_hidden = true` so
they render with the dimmed hidden style.

Based on: stevearc/oil.nvim#473

* docs(upstream): fix formatting

* docs(upstream): update #213 and #473 with PR and commit links
This commit is contained in:
Barrett Ruth 2026-03-07 16:52:57 -05:00 committed by GitHub
parent a9a06b8f3b
commit 4a8d57a269
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 62 additions and 3 deletions

View file

@ -152,6 +152,9 @@ The full list of options with their defaults:
view_options = {
-- Show files and directories that start with "."
show_hidden = false,
-- When true and a directory has no visible entries, show hidden entries
-- instead of an empty listing. is_always_hidden entries are never shown.
show_hidden_when_empty = false,
-- This function defines what is considered a "hidden" file
is_hidden_file = function(name, bufnr)
local m = name:match("^%.")
@ -227,6 +230,10 @@ The full list of options with their defaults:
disable_preview = function(filename)
return false
end,
-- Maximum file size in MB to load into the preview window. Files larger
-- than this limit will show a placeholder message instead of being loaded.
-- Set to nil to disable the limit.
max_file_size = 10,
-- Window-local options to use for preview window buffers
win_options = {},
},
@ -328,6 +335,19 @@ cleanup_buffers_on_delete *canola.cleanup_buffers_on_de
was successfully deleted via canola. This prevents stale buffers from
appearing in the jumplist after a deletion.
show_hidden_when_empty *canola.show_hidden_when_empty*
type: `boolean` default: `false`
When `true` and a directory contains no visible entries (because all
entries are hidden), canola will display the hidden entries anyway.
Entries matching `is_always_hidden` are never shown. Hidden entries
are still rendered with the dimmed hidden style.
preview_win.max_file_size *canola.preview_win*
type: `number` default: `10`
Maximum file size in MB to load into the preview window. Files larger
than this limit will show a placeholder message instead of being loaded.
Set to `nil` to disable the limit.
--------------------------------------------------------------------------------
API *canola-api*

View file

@ -35,6 +35,8 @@ Bugs fixed in this fork that remain open upstream.
| [#670](https://github.com/stevearc/oil.nvim/issues/670) | Multi-directory cmdline args ignored | [#11](https://github.com/barrettruth/canola.nvim/pull/11) ([`70861e5`](https://github.com/barrettruth/canola.nvim/commit/70861e5)) |
| [#673](https://github.com/stevearc/oil.nvim/issues/673) | Symlink newlines crash | [`9110a1a`](https://github.com/barrettruth/canola.nvim/commit/9110a1a) |
| [#710](https://github.com/stevearc/oil.nvim/issues/710) | buftype empty on BufEnter | [#10](https://github.com/barrettruth/canola.nvim/pull/10) ([`01b860e`](https://github.com/barrettruth/canola.nvim/commit/01b860e)) |
| [#213](https://github.com/stevearc/oil.nvim/issues/213) | Max file size for preview | [#85](https://github.com/barrettruth/canola.nvim/pull/85) ([`4b32ada`](https://github.com/barrettruth/canola.nvim/commit/4b32ada)) |
| [#473](https://github.com/stevearc/oil.nvim/issues/473) | Show hidden when dir is all-hidden | [#85](https://github.com/barrettruth/canola.nvim/pull/85) ([`2fe4e78`](https://github.com/barrettruth/canola.nvim/commit/2fe4e78)) |
## Open upstream PRs
@ -61,7 +63,7 @@ Bugs fixed in this fork that remain open upstream.
| [#200](https://github.com/stevearc/oil.nvim/issues/200) | open | Highlights not working when opening a file (P2) |
| [#207](https://github.com/stevearc/oil.nvim/issues/207) | open | Suppress "no longer available" message (P1) |
| [#210](https://github.com/stevearc/oil.nvim/issues/210) | open | FTP support (P2) |
| [#213](https://github.com/stevearc/oil.nvim/issues/213) | open | Disable preview for large files (P1) |
| [#213](https://github.com/stevearc/oil.nvim/issues/213) | fixed | Disable preview for large files — `preview_win.max_file_size` (P1) |
| [#226](https://github.com/stevearc/oil.nvim/issues/226) | open | K8s/Docker adapter (P2) |
| [#232](https://github.com/stevearc/oil.nvim/issues/232) | open | Cannot close last window (P2) |
| [#254](https://github.com/stevearc/oil.nvim/issues/254) | open | Buffer modified highlight group (P2) |
@ -104,7 +106,7 @@ Bugs fixed in this fork that remain open upstream.
| [#450](https://github.com/stevearc/oil.nvim/issues/450) | open | Highlight opened file in directory listing |
| [#457](https://github.com/stevearc/oil.nvim/issues/457) | open | Custom column API |
| [#466](https://github.com/stevearc/oil.nvim/issues/466) | open | Select into window on right |
| [#473](https://github.com/stevearc/oil.nvim/issues/473) | open | Show all hidden files if dir only has hidden |
| [#473](https://github.com/stevearc/oil.nvim/issues/473) | fixed | Show all hidden files if dir only has hidden — `view_options.show_hidden_when_empty` |
| [#479](https://github.com/stevearc/oil.nvim/issues/479) | open | Harpoon integration recipe |
| [#483](https://github.com/stevearc/oil.nvim/issues/483) | not actionable | Spell downloads depend on netrw — fixed in [neovim#34940](https://github.com/neovim/neovim/pull/34940) |
| [#486](https://github.com/stevearc/oil.nvim/issues/486) | open | All directory sizes show 4.1k |