From f03962c6170819300d703bd542fff4a01b8429e6 Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Mon, 17 Jan 2022 13:18:17 -0800 Subject: [PATCH] fix(input): expand width to fit prompt & default --- lua/dressing/input.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lua/dressing/input.lua b/lua/dressing/input.lua index 9186e92..ba12184 100644 --- a/lua/dressing/input.lua +++ b/lua/dressing/input.lua @@ -172,7 +172,16 @@ setmetatable(M, { -- Create or update the window local prompt = opts.prompt or config.default_prompt - local width = util.calculate_width(config.prefer_width, config) + + -- First calculate the desired base width of the modal + local prefer_width = util.calculate_width(config.prefer_width, config) + -- Then expand the width to fit the prompt and default value + prefer_width = math.max(prefer_width, 4 + vim.api.nvim_strwidth(prompt)) + if opts.default then + prefer_width = math.max(prefer_width, 2 + vim.api.nvim_strwidth(opts.default)) + end + -- Then recalculate to clamp final value to min/max + local width = util.calculate_width(prefer_width, config) local winopt = { relative = config.relative, anchor = config.anchor,