mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 10:49:08 +00:00
feat(picker): allow adding custom layouts to opts.picker.layouts
This commit is contained in:
parent
27320b14c9
commit
7efed2e40f
3 changed files with 13 additions and 4 deletions
|
@ -75,6 +75,7 @@ local M = {}
|
|||
---@field icons? snacks.picker.icons
|
||||
---@field source? string
|
||||
---@field on_moved? fun(picker:snacks.Picker, item:snacks.picker.Item)
|
||||
---@field layouts? table<string, snacks.picker.Layout>
|
||||
local defaults = {
|
||||
prompt = " ",
|
||||
sources = {},
|
||||
|
|
|
@ -18,7 +18,13 @@ function M.get(opts)
|
|||
opts.source and global.sources[opts.source] or {},
|
||||
opts,
|
||||
}
|
||||
return vim.tbl_deep_extend("force", unpack(todo))
|
||||
local ret = vim.tbl_deep_extend("force", unpack(todo))
|
||||
ret.layouts = ret.layouts or {}
|
||||
local layouts = require("snacks.picker.config.layouts")
|
||||
for k, v in pairs(layouts or {}) do
|
||||
ret.layouts[k] = ret.layouts[k] or v
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
--- Resolve the layout configuration
|
||||
|
@ -31,7 +37,7 @@ function M.layout(opts)
|
|||
return layout
|
||||
end
|
||||
local preset = M.resolve(layout.preset or "custom", opts.source)
|
||||
local ret = vim.deepcopy(layouts[preset] or {})
|
||||
local ret = vim.deepcopy(opts.layouts and opts.layouts[preset] or layouts[preset] or {})
|
||||
ret = vim.tbl_deep_extend("force", ret, layout or {})
|
||||
ret.preset = nil
|
||||
return ret
|
||||
|
|
|
@ -25,8 +25,10 @@ function M.pickers(opts)
|
|||
return M.table("picker/config/sources.lua", opts.sources or {})
|
||||
end
|
||||
|
||||
function M.layouts()
|
||||
return M.table("picker/config/layouts.lua", require("snacks.picker.config.layouts"))
|
||||
---@param opts snacks.picker.Config
|
||||
---@type snacks.picker.finder
|
||||
function M.layouts(opts)
|
||||
return M.table("picker/config/layouts.lua", opts.layouts or {})
|
||||
end
|
||||
|
||||
function M.actions()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue