feat(input): option to allow normal mode (#3)

This commit is contained in:
Steven Arcangeli 2021-12-05 19:20:15 -08:00
parent 7e6e962341
commit 08c0cf3217
2 changed files with 8 additions and 7 deletions

View File

@ -3,6 +3,9 @@ local default_config = {
-- Default prompt string
default_prompt = "",
-- When true, <Esc> will close the modal
insert_only = true,
-- These are passed to nvim_open_win
anchor = "SW",
relative = "cursor",

View File

@ -149,13 +149,11 @@ setmetatable(M, {
vim.api.nvim_buf_set_option(bufnr, "swapfile", false)
vim.api.nvim_buf_set_option(bufnr, "bufhidden", "wipe")
local keyopts = { silent = true, noremap = true }
vim.api.nvim_buf_set_keymap(
bufnr,
"i",
"<Esc>",
"<cmd>lua require('dressing.input').confirm()<CR>",
keyopts
)
local close_rhs = "<cmd>lua require('dressing.input').confirm()<CR>"
vim.api.nvim_buf_set_keymap(bufnr, "n", "<Esc>", close_rhs, keyopts)
if config.insert_only then
vim.api.nvim_buf_set_keymap(bufnr, "i", "<Esc>", close_rhs, keyopts)
end
vim.fn.prompt_setprompt(bufnr, prompt)
-- Would prefer to use v:lua directly here, but it doesn't work :(
vim.fn.prompt_setcallback(bufnr, "dressing#prompt_confirm")