diff --git a/lua/dressing/config.lua b/lua/dressing/config.lua index 0cb3b8a..8377b8f 100644 --- a/lua/dressing/config.lua +++ b/lua/dressing/config.lua @@ -12,6 +12,9 @@ local default_config = { -- When true, 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", diff --git a/lua/dressing/input.lua b/lua/dressing/input.lua index e26b693..6abf19b 100644 --- a/lua/dressing/input.lua +++ b/lua/dressing/input.lua @@ -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), diff --git a/tests/input_spec.lua b/tests/input_spec.lua index c5e4af3..ca0cad7 100644 --- a/tests/input_spec.lua +++ b/tests/input_spec.lua @@ -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", + "", + }, { + 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)