fix(nui): prevent double-callback in ui.select (#131)

This commit is contained in:
Steven Arcangeli 2023-12-26 17:39:19 +00:00
parent 8b7ae53d7f
commit 94b0d24483
1 changed files with 11 additions and 2 deletions

View File

@ -24,6 +24,13 @@ M.select = function(config, items, opts, on_choice)
}
end
local callback
callback = function(...)
on_choice(...)
-- Prevent double-calls
callback = function() end
end
local border = vim.deepcopy(config.border)
border.text = {
top = opts.prompt,
@ -48,10 +55,12 @@ M.select = function(config, items, opts, on_choice)
submit = { "<CR>" },
},
on_close = function()
on_choice(nil, nil)
vim.schedule(function()
callback(nil, nil)
end)
end,
on_submit = function(item)
on_choice(item.value, item.idx)
callback(item.value, item.idx)
end,
})