Skip to content

Commit

Permalink
feat: allow mode to be set on a single mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed May 5, 2021
1 parent 402be18 commit 2a08d58
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lua/which-key/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ function M.parse_mappings(mappings, value, prefix)
mapping.opts.noremap = v
elseif k == "silent" then
mapping.opts.silent = v
elseif k == "mode" then
mapping.mode = v
elseif k == "plugin" then
mapping.group = true
mapping.plugin = v
Expand Down Expand Up @@ -223,6 +225,7 @@ function M.register(mappings, opts)
for _, mapping in pairs(mappings) do
if opts.buffer and not mapping.buf then mapping.buf = opts.buffer end
mapping.keys = Util.parse_keys(mapping.prefix)
mapping.mode = mapping.mode or mode
if mapping.cmd then
mapping.opts = vim.tbl_deep_extend("force", { silent = true, noremap = true }, opts,
mapping.opts or {})
Expand All @@ -232,9 +235,9 @@ function M.register(mappings, opts)
nowait = mapping.opts.nowait or false,
}
if mapping.cmd:lower():sub(1, #("<plug>")) == "<plug>" then keymap_opts.noremap = false end
M.map(mode, mapping.prefix, mapping.cmd, mapping.buf, keymap_opts)
M.map(mapping.mode, mapping.prefix, mapping.cmd, mapping.buf, keymap_opts)
end
M.get_tree(mode, mapping.buf).tree:add(mapping)
M.get_tree(mapping.mode, mapping.buf).tree:add(mapping)
end
end

Expand Down

0 comments on commit 2a08d58

Please sign in to comment.