feat: use scratch buffer for file previews (#467)

* Initial implementation of scratch based preview

* Fix call to buf is valid in loop

* Fixing call to be made only from the main event loop

* Improve handling of large files from @pkazmier

* Better error handling and simplifying the code

* Default to old behavior

* Add documentation

* Fix readfile

* Fix the configuration

* refactor: single config enum and load real buffer on BufEnter

* doc: regenerate documentation

---------

Co-authored-by: Steven Arcangeli <stevearc@stevearc.com>
This commit is contained in:
Jalal El Mansouri 2024-11-20 02:24:24 +01:00 committed by GitHub
parent 8ea40b5506
commit 21705a1deb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 79 additions and 21 deletions

View file

@ -142,8 +142,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,
-- How to open the preview window "load"|"scratch"|"fast_scratch"
preview_method = "fast_scratch",
-- Window-local options to use for preview window buffers
win_options = {},
},
@ -326,16 +326,21 @@ local M = {}
---@field border? string|string[] Window border
---@field win_options? table<string, any>
---@alias oil.PreviewMethod
---| '"load"' # Load the previewed file into a buffer
---| '"scratch"' # Put the text into a scratch buffer to avoid LSP attaching
---| '"fast_scratch"' # Put only the visible text into a scratch buffer
---@class (exact) oil.PreviewWindowConfig
---@field update_on_cursor_moved boolean
---@field max_file_size_mb number
---@field preview_method oil.PreviewMethod
---@field win_options table<string, any>
---@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
---@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
---@class (exact) oil.SetupConfirmationWindowConfig : oil.SetupWindowConfig