Skip to content

Commit

Permalink
fix!: update vim.ui.input to match nvim 0.9 API
Browse files Browse the repository at this point in the history
neovim/neovim#20883 changed the behavior of
vim.ui.input. The main change was that inputting no text now returns an
empty string instead of nil.
  • Loading branch information
stevearc committed Nov 9, 2022
1 parent 2319ee2 commit 202bcf6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 0 additions & 3 deletions lua/dressing/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ local function confirm(text)
-- deleted from the buffer after the input window closes.
vim.defer_fn(function()
pcall(vim.api.nvim_win_close, ctx.winid, true)
if text == "" then
text = nil
end
if text and history[#history] ~= text then
table.insert(history, text)
end
Expand Down
22 changes: 22 additions & 0 deletions tests/input_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ a.describe("input modal", function()
assert(ret == "my text", string.format("Got '%s' expected 'my text'", ret))
end)

a.it("returns cancelreturn when input is canceled <C-c>", function()
local ret = run_input({
"my text",
"<C-c>",
}, { cancelreturn = "CANCELED" })
assert(ret == "CANCELED", string.format("Got '%s' expected nil", ret))
end)

a.it("returns empty string when input is empty", function()
local ret = run_input({
"<CR>",
})
assert(ret == "", string.format("Got '%s' expected nil", ret))
end)

a.it("returns empty string when input is empty, even if cancelreturn set", function()
local ret = run_input({
"<CR>",
}, { cancelreturn = "CANCELED" })
assert(ret == "", string.format("Got '%s' expected nil", ret))
end)

a.it("starts in normal mode when start_in_insert = false", function()
local orig_cmd = vim.cmd
local startinsert_called = false
Expand Down

0 comments on commit 202bcf6

Please sign in to comment.