feat(picker): added none preview that simply shows a warning message

This commit is contained in:
Folke Lemaitre 2025-01-14 21:31:31 +01:00
parent 2a53288994
commit 65ad0f6a23
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 13 additions and 1 deletions

View file

@ -57,6 +57,7 @@ M.command_history = {
finder = "vim_history",
name = "cmd",
format = "text",
preview = "none",
layout = {
preset = "vscode",
},
@ -486,6 +487,7 @@ M.search_history = {
finder = "vim_history",
name = "search",
format = "text",
preview = "none",
layout = {
preset = "vscode",
},

View file

@ -31,6 +31,12 @@ function M.directory(ctx)
end
end
---@param ctx snacks.picker.preview.ctx
function M.none(ctx)
ctx.preview:reset()
ctx.preview:notify("no preview available", "warn")
end
---@param ctx snacks.picker.preview.ctx
function M.preview(ctx)
if ctx.item.preview == "file" then
@ -52,7 +58,11 @@ function M.file(ctx)
ctx.preview:set_title(name)
vim.api.nvim_win_set_buf(ctx.win, ctx.item.buf)
else
local path = assert(Snacks.picker.util.path(ctx.item), "item.file is required: " .. vim.inspect(ctx.item))
local path = Snacks.picker.util.path(ctx.item)
if not path then
ctx.preview:notify("Item has no `file`", "error")
return
end
-- re-use existing preview when path is the same
if path ~= Snacks.picker.util.path(ctx.prev) then
ctx.preview:reset()