diff --git a/lua/dressing/config.lua b/lua/dressing/config.lua index 99f936a..0cb3b8a 100644 --- a/lua/dressing/config.lua +++ b/lua/dressing/config.lua @@ -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 diff --git a/lua/dressing/select/nui.lua b/lua/dressing/select/nui.lua index 0168537..6490392 100644 --- a/lua/dressing/select/nui.lua +++ b/lua/dressing/select/nui.lua @@ -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,