Merge pull request #83 from uga-rosa/master

feat: allow to pass extra opts to vim.keymap.set()
This commit is contained in:
Steven Arcangeli 2023-02-05 11:43:51 -08:00 committed by GitHub
commit 1a7f062ab3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View File

@ -158,6 +158,8 @@ require('dressing').setup({
mappings = { mappings = {
n = { n = {
["<Esc>"] = "Close", ["<Esc>"] = "Close",
-- You can also pass additional opts to vim.keymap.set().
-- ["<Esc>"] = { "Close", nowait = true },
["<CR>"] = "Confirm", ["<CR>"] = "Confirm",
}, },
i = { i = {

View File

@ -48,6 +48,8 @@ Configure dressing.nvim by calling the setup() function.
mappings = { mappings = {
n = { n = {
["<Esc>"] = "Close", ["<Esc>"] = "Close",
-- You can also pass additional opts to vim.keymap.set().
-- ["<Esc>"] = { "Close", nowait = true },
["<CR>"] = "Confirm", ["<CR>"] = "Confirm",
}, },
i = { i = {

View File

@ -8,7 +8,7 @@ end
---@param bufnr number ---@param bufnr number
---@param mode string ---@param mode string
---@param bindings table<string, string> ---@param bindings table<string, string|table>
---@param prefix string ---@param prefix string
M.create_maps_to_plug = function(bufnr, mode, bindings, prefix) M.create_maps_to_plug = function(bufnr, mode, bindings, prefix)
local maps local maps
@ -17,6 +17,16 @@ M.create_maps_to_plug = function(bufnr, mode, bindings, prefix)
end end
for lhs, rhs in pairs(bindings) do for lhs, rhs in pairs(bindings) do
if rhs then if rhs then
local opts = { buffer = bufnr, remap = true }
if type(rhs) == "table" then
for k, v in pairs(rhs) do
if type(k) == "string" then
opts[k] = v
elseif k == 1 then
rhs = v
end
end
end
-- Prefix with <Plug> unless this is a <Cmd> or :Cmd mapping -- Prefix with <Plug> unless this is a <Cmd> or :Cmd mapping
if type(rhs) == "string" and not rhs:match("[<:]") then if type(rhs) == "string" and not rhs:match("[<:]") then
rhs = "<Plug>" .. prefix .. rhs rhs = "<Plug>" .. prefix .. rhs
@ -30,7 +40,7 @@ M.create_maps_to_plug = function(bufnr, mode, bindings, prefix)
end end
end end
end end
vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, remap = true }) vim.keymap.set(mode, lhs, rhs, opts)
end end
end end
end end