Closed Shatur closed 2 years ago
This is intentional behavior. The built-in vim.ui.input
explicitly treats an empty return string as nil
, so we have to do the same to preserve compatibility.
https://github.com/neovim/neovim/blob/0adc66171a355a12494d87ebb767d509540c7ef9/runtime/lua/vim/ui.lua#L92-L96
Oh, I see... But how can I know if a user canceled the dialog or set an empty string?
Unfortunately, you cannot. I believe this is a limitation of the input()
function, which seems to return an empty string when canceled. Since it can't distinguish between empty input and cancel, vim.ui.input
can't either.
Describe the bug
The following code
prints
nil
for both cancelled dialog and empty input. I would expect to have an empty string on empty input.System information
To Reproduce Steps to reproduce the behavior:
:vim.ui.input({ prompt = 'Data: ' }, function(data) vim.notify(vim.inspect(data)) end)
<CR>