mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 02:38:46 +00:00
fix(picker.preview): only show binary message when binary and no ft. Closes #729
This commit is contained in:
parent
a17090d6cd
commit
ea838e2838
1 changed files with 13 additions and 2 deletions
|
@ -109,6 +109,11 @@ function M.file(ctx)
|
|||
|
||||
local file = assert(io.open(path, "r"))
|
||||
|
||||
local is_binary = false
|
||||
local ft = ctx.picker.opts.previewers.file.ft or vim.filetype.match({ filename = path })
|
||||
if ft == "bigfile" then
|
||||
ft = nil
|
||||
end
|
||||
local lines = {}
|
||||
for line in file:lines() do
|
||||
---@cast line string
|
||||
|
@ -117,14 +122,20 @@ function M.file(ctx)
|
|||
end
|
||||
-- Check for binary data in the current line
|
||||
if line:find("[%z\1-\8\11\12\14-\31]") then
|
||||
ctx.preview:notify("binary file", "warn")
|
||||
return
|
||||
is_binary = true
|
||||
if not ft then
|
||||
ctx.preview:notify("binary file", "warn")
|
||||
return
|
||||
end
|
||||
end
|
||||
table.insert(lines, line)
|
||||
end
|
||||
|
||||
file:close()
|
||||
|
||||
if is_binary then
|
||||
ctx.preview:wo({ number = false, relativenumber = false, cursorline = false, signcolumn = "no" })
|
||||
end
|
||||
ctx.preview:set_lines(lines)
|
||||
ctx.preview:highlight({ file = path, ft = ctx.picker.opts.previewers.file.ft, buf = ctx.buf })
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue