feat(input): add start_in_insert option

Add a new option, start_in_insert, that defaults to true and controls
whether the input will start in insert or normal mode.
This commit is contained in:
Michael Benford 2022-07-20 14:40:25 -03:00
parent 1e60c07ae9
commit 28cb494b61
3 changed files with 28 additions and 1 deletions

View File

@ -12,6 +12,9 @@ local default_config = {
-- When true, <Esc> will close the modal
insert_only = true,
-- When true, input will start in insert mode.
start_in_insert = true,
-- These are passed to nvim_open_win
anchor = "SW",
border = "rounded",

View File

@ -333,7 +333,9 @@ setmetatable(M, {
aug END
]])
vim.cmd("startinsert!")
if config.start_in_insert then
vim.cmd("startinsert!")
end
close_completion_window()
M.highlight()
end),

View File

@ -78,6 +78,28 @@ a.describe("input modal", function()
assert(ret == "my text", string.format("Got '%s' expected 'my text'", ret))
end)
a.it("starts in normal mode when start_in_insert = false", function()
local orig_cmd = vim.cmd
local startinsert_called = false
vim.cmd = function(cmd)
if cmd == "startinsert!" then
startinsert_called = true
end
orig_cmd(cmd)
end
require("dressing.config").input.start_in_insert = false
run_input({
"my text",
"<CR>",
}, {
after_fn = function()
vim.cmd = orig_cmd
end,
})
assert(not startinsert_called, "Got 'true' expected 'false'")
end)
a.it("cancels first callback if second input is opened", function()
local tx, rx = channel.oneshot()
vim.ui.input({}, tx)