Skip to content

Commit

Permalink
fix: format_item doesn't have to return a string
Browse files Browse the repository at this point in the history
This is perhaps ambiguous from the core docs, but format_item can return
values that are not strings and they will then be stringified. So we
should do the same
  • Loading branch information
stevearc committed Dec 4, 2021
1 parent 18a3548 commit 7d0e85f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lua/dressing/select/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ return function(items, opts, on_choice)
opts = opts or {}
local config = global_config.get_mod_config("select", opts)
opts.prompt = opts.prompt or "Select one of:"
opts.format_item = opts.format_item or tostring
if opts.format_item then
-- Make format_item doesn't *technically* have to return a string for the
-- core implementation. We should maintain compatibility by wrapping the
-- return value with tostring
local format_item = opts.format_item
opts.format_item = function(item)
return tostring(format_item(item))
end
else
opts.format_item = tostring
end

local backend, name = get_backend(config)
backend.select(config[name], items, opts, on_choice)
Expand Down

0 comments on commit 7d0e85f

Please sign in to comment.