fix: image.nvim previews with preview_method=scratch
This commit is contained in:
parent
bf81e2a79a
commit
5acab3d8a9
2 changed files with 27 additions and 1 deletions
|
|
@ -534,7 +534,11 @@ 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 entry_is_file and config.preview_win.preview_method ~= "load" then
|
if
|
||||||
|
entry_is_file
|
||||||
|
and config.preview_win.preview_method ~= "load"
|
||||||
|
and not util.file_matches_bufreadcmd(normalized_url)
|
||||||
|
then
|
||||||
filebufnr =
|
filebufnr =
|
||||||
util.read_file_to_scratch_buffer(normalized_url, config.preview_win.preview_method)
|
util.read_file_to_scratch_buffer(normalized_url, config.preview_win.preview_method)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -952,4 +952,26 @@ M.read_file_to_scratch_buffer = function(path, preview_method)
|
||||||
return bufnr
|
return bufnr
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local _regcache = {}
|
||||||
|
---Check if a file matches a BufReadCmd autocmd
|
||||||
|
---@param filename string
|
||||||
|
---@return boolean
|
||||||
|
M.file_matches_bufreadcmd = function(filename)
|
||||||
|
local autocmds = vim.api.nvim_get_autocmds({
|
||||||
|
event = "BufReadCmd",
|
||||||
|
})
|
||||||
|
for _, au in ipairs(autocmds) do
|
||||||
|
local pat = _regcache[au.pattern]
|
||||||
|
if not pat then
|
||||||
|
pat = vim.fn.glob2regpat(au.pattern)
|
||||||
|
_regcache[au.pattern] = pat
|
||||||
|
end
|
||||||
|
|
||||||
|
if vim.fn.match(filename, pat) >= 0 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue