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:
parent
1e60c07ae9
commit
28cb494b61
|
@ -12,6 +12,9 @@ local default_config = {
|
||||||
-- When true, <Esc> will close the modal
|
-- When true, <Esc> will close the modal
|
||||||
insert_only = true,
|
insert_only = true,
|
||||||
|
|
||||||
|
-- When true, input will start in insert mode.
|
||||||
|
start_in_insert = true,
|
||||||
|
|
||||||
-- These are passed to nvim_open_win
|
-- These are passed to nvim_open_win
|
||||||
anchor = "SW",
|
anchor = "SW",
|
||||||
border = "rounded",
|
border = "rounded",
|
||||||
|
|
|
@ -333,7 +333,9 @@ setmetatable(M, {
|
||||||
aug END
|
aug END
|
||||||
]])
|
]])
|
||||||
|
|
||||||
vim.cmd("startinsert!")
|
if config.start_in_insert then
|
||||||
|
vim.cmd("startinsert!")
|
||||||
|
end
|
||||||
close_completion_window()
|
close_completion_window()
|
||||||
M.highlight()
|
M.highlight()
|
||||||
end),
|
end),
|
||||||
|
|
|
@ -78,6 +78,28 @@ a.describe("input modal", function()
|
||||||
assert(ret == "my text", string.format("Got '%s' expected 'my text'", ret))
|
assert(ret == "my text", string.format("Got '%s' expected 'my text'", ret))
|
||||||
end)
|
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()
|
a.it("cancels first callback if second input is opened", function()
|
||||||
local tx, rx = channel.oneshot()
|
local tx, rx = channel.oneshot()
|
||||||
vim.ui.input({}, tx)
|
vim.ui.input({}, tx)
|
||||||
|
|
Loading…
Reference in New Issue