Skip to content

Commit

Permalink
fix(input): expand width to fit prompt & default
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Jan 17, 2022
1 parent 25b7262 commit f03962c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lua/dressing/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f03962c

Please sign in to comment.