mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 10:49:08 +00:00
feat(picker): added none
preview that simply shows a warning message
This commit is contained in:
parent
2a53288994
commit
65ad0f6a23
2 changed files with 13 additions and 1 deletions
|
@ -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",
|
||||
},
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue