Skip to content

Commit

Permalink
feat(input): option to allow normal mode (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Dec 6, 2021
1 parent 7e6e962 commit 08c0cf3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 3 additions & 0 deletions lua/dressing/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 5 additions & 7 deletions lua/dressing/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 08c0cf3

Please sign in to comment.