fix: disable_preview respected when preview_method != "load" (#577)

* fix bug of disable_preview

file should not loaded if disable_preview is true

* refeactor function open_preview about disable_preview

switch the condition checking `disable_preview` of `if`
move the longer condition to the `elseif`
swap their repective code blocks to maintain the same functionality

* refactor: simplify conditionals

* fix: missing then

---------

Co-authored-by: Steven Arcangeli <506791+stevearc@users.noreply.github.com>
This commit is contained in:
forestchen1224 2025-02-14 06:22:54 +08:00 committed by GitHub
parent 32dd3e378d
commit 7cde5aab10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -556,18 +556,19 @@ M.open_preview = function(opts, callback)
local entry_is_file = not vim.endswith(normalized_url, "/") local entry_is_file = not vim.endswith(normalized_url, "/")
local filebufnr local filebufnr
if if entry_is_file then
entry_is_file if config.preview_win.disable_preview(normalized_url) then
and config.preview_win.preview_method ~= "load" filebufnr = vim.api.nvim_create_buf(false, true)
and not util.file_matches_bufreadcmd(normalized_url) vim.bo[filebufnr].bufhidden = "wipe"
then vim.bo[filebufnr].buftype = "nofile"
filebufnr = util.render_text(filebufnr, "Preview disabled", { winid = preview_win })
util.read_file_to_scratch_buffer(normalized_url, config.preview_win.preview_method) elseif
elseif entry_is_file and config.preview_win.disable_preview(normalized_url) then config.preview_win.preview_method ~= "load"
filebufnr = vim.api.nvim_create_buf(false, true) and not util.file_matches_bufreadcmd(normalized_url)
vim.bo[filebufnr].bufhidden = "wipe" then
vim.bo[filebufnr].buftype = "nofile" filebufnr =
util.render_text(filebufnr, "Preview disabled", { winid = preview_win }) util.read_file_to_scratch_buffer(normalized_url, config.preview_win.preview_method)
end
end end
if not filebufnr then if not filebufnr then