feat(picker): opening a picker with the same source as an active picker, will close it instead (toggle)

This commit is contained in:
Folke Lemaitre 2025-01-30 10:35:45 +01:00
parent 92710dfb0b
commit b6cf033051

View file

@ -17,6 +17,9 @@ local M = setmetatable({}, {
end,
---@param M snacks.picker
__index = function(M, k)
if k == "current" then
return nil
end
if type(k) ~= "string" then
return
end
@ -69,6 +72,10 @@ function M.pick(source, opts)
opts.source = "pickers"
return M.pick(opts)
end
if opts.source and M.current and M.current.opts.source == opts.source then
M.current:close()
return
end
return require("snacks.picker.core.picker").new(opts)
end