mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
This commit is contained in:
parent
eb75825f83
commit
d05071255c
1 changed files with 9 additions and 6 deletions
|
|
@ -9,11 +9,15 @@ function M.directory(ctx)
|
|||
ctx.preview:reset()
|
||||
ctx.preview:minimal()
|
||||
local path = Snacks.picker.util.path(ctx.item)
|
||||
local name = path and vim.fn.fnamemodify(path, ":t")
|
||||
if not path then
|
||||
ctx.preview:notify("Item has no `file`", "error")
|
||||
return
|
||||
end
|
||||
local name = vim.fn.fnamemodify(path, ":t")
|
||||
ctx.preview:set_title(ctx.item.title or name)
|
||||
local ls = {} ---@type {file:string, type:"file"|"directory"}[]
|
||||
for file, t in vim.fs.dir(ctx.item.file) do
|
||||
t = t or Snacks.util.path_type(ctx.item.file .. "/" .. file)
|
||||
for file, t in vim.fs.dir(path) do
|
||||
t = t or Snacks.util.path_type(path .. "/" .. file)
|
||||
ls[#ls + 1] = { file = file, type = t }
|
||||
end
|
||||
ctx.preview:set_lines(vim.split(string.rep("\n", #ls), "\n"))
|
||||
|
|
@ -27,11 +31,10 @@ function M.directory(ctx)
|
|||
local is_dir = item.type == "directory"
|
||||
local cat = is_dir and "directory" or "file"
|
||||
local hl = is_dir and "Directory" or nil
|
||||
local path = item.file
|
||||
local icon, icon_hl = Snacks.util.icon(path, cat, {
|
||||
local icon, icon_hl = Snacks.util.icon(item.file, cat, {
|
||||
fallback = ctx.picker.opts.icons.files,
|
||||
})
|
||||
local line = { { icon .. " ", icon_hl }, { path, hl } }
|
||||
local line = { { icon .. " ", icon_hl }, { item.file, hl } }
|
||||
vim.api.nvim_buf_set_extmark(ctx.buf, ns, i - 1, 0, {
|
||||
virt_text = line,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue