feat(select)(nui): add more configuration options
This commit is contained in:
parent
1706d00209
commit
a59218e110
|
@ -79,8 +79,17 @@ local default_config = {
|
|||
border = {
|
||||
style = "rounded",
|
||||
},
|
||||
buf_options = {
|
||||
swapfile = false,
|
||||
filetype = "DressingSelect",
|
||||
},
|
||||
win_options = {
|
||||
winblend = 10,
|
||||
},
|
||||
max_width = 80,
|
||||
max_height = 40,
|
||||
min_width = 40,
|
||||
min_height = 10,
|
||||
},
|
||||
|
||||
-- Options for built-in selector
|
||||
|
|
|
@ -8,8 +8,20 @@ M.select = function(config, items, opts, on_choice)
|
|||
local Menu = require("nui.menu")
|
||||
local event = require("nui.utils.autocmd").event
|
||||
local lines = {}
|
||||
local line_width = 1
|
||||
for i, item in ipairs(items) do
|
||||
table.insert(lines, Menu.item(opts.format_item(item), { value = item, idx = i }))
|
||||
local line = opts.format_item(item)
|
||||
line_width = math.max(line_width, vim.api.nvim_strwidth(line))
|
||||
table.insert(lines, Menu.item(item, { value = item, idx = i }))
|
||||
end
|
||||
|
||||
if not config.size then
|
||||
line_width = math.max(line_width, config.min_width)
|
||||
local height = math.max(#lines, config.min_height)
|
||||
config.size = {
|
||||
width = line_width,
|
||||
height = height,
|
||||
}
|
||||
end
|
||||
|
||||
local border = vim.deepcopy(config.border)
|
||||
|
@ -22,12 +34,8 @@ M.select = function(config, items, opts, on_choice)
|
|||
size = config.size,
|
||||
relative = config.relative,
|
||||
border = border,
|
||||
buf_options = {
|
||||
swapfile = false,
|
||||
},
|
||||
win_options = {
|
||||
winblend = 10,
|
||||
},
|
||||
buf_options = config.buf_options,
|
||||
win_options = config.win_options,
|
||||
enter = true,
|
||||
}, {
|
||||
lines = lines,
|
||||
|
|
Loading…
Reference in New Issue