Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lua): use empty_dict when no opts given in vim.ui.input #19109

Merged
merged 1 commit into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions runtime/doc/lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1935,8 +1935,7 @@ input({opts}, {on_confirm}) *vim.ui.input()*

Parameters: ~
{opts} (table) Additional options. See |input()|
• prompt (string|nil) Text of the prompt.
Defaults to `Input:`.
• prompt (string|nil) Text of the prompt
• default (string|nil) Default reply to the
input
• completion (string|nil) Specifies type of
Expand Down
4 changes: 2 additions & 2 deletions runtime/lua/vim/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ end
---
---@param opts table Additional options. See |input()|
--- - prompt (string|nil)
--- Text of the prompt. Defaults to `Input: `.
--- Text of the prompt
--- - default (string|nil)
--- Default reply to the input
--- - completion (string|nil)
Expand Down Expand Up @@ -87,7 +87,7 @@ function M.input(opts, on_confirm)
on_confirm = { on_confirm, 'function', false },
})

opts = opts or {}
opts = (opts and not vim.tbl_isempty(opts)) and opts or vim.empty_dict()
local input = vim.fn.input(opts)
if #input > 0 then
on_confirm(input)
Expand Down
16 changes: 16 additions & 0 deletions test/functional/lua/ui_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ local helpers = require('test.functional.helpers')(after_each)
local eq = helpers.eq
local exec_lua = helpers.exec_lua
local clear = helpers.clear
local feed = helpers.feed
local eval = helpers.eval

describe('vim.ui', function()
before_each(function()
Expand Down Expand Up @@ -67,5 +69,19 @@ describe('vim.ui', function()
eq('Inputted text', result[1])
eq('Input: ', result[2])
end)

it('can input text on nil opt', function()
feed(':lua vim.ui.input(nil, function(input) result = input end)<cr>')
eq('', eval('v:errmsg'))
feed('Inputted text<cr>')
eq('Inputted text', exec_lua('return result'))
end)

it('can input text on {} opt', function()
feed(':lua vim.ui.input({}, function(input) result = input end)<cr>')
eq('', eval('v:errmsg'))
feed('abcdefg<cr>')
eq('abcdefg', exec_lua('return result'))
end)
end)
end)