diff options
| author | ADoyle <adoyle.h@gmail.com> | 2022-11-07 00:42:29 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-06 17:42:29 +0100 |
| commit | d541e0d6e00a0d89f21e1b0e6fe92c736ac0f83b (patch) | |
| tree | 97e583b055ffb8fbdd5bdb3865a106eae20a2c3c /lua/telescope/mappings.lua | |
| parent | 30826fcfb8dd8c63cb3d69e72e23b1f037170f35 (diff) | |
feat: the parameter "map" of attach_mappings can be list of modes to create mapping on multiple modes (#2220)
Diffstat (limited to 'lua/telescope/mappings.lua')
| -rw-r--r-- | lua/telescope/mappings.lua | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lua/telescope/mappings.lua b/lua/telescope/mappings.lua index e5b23bc..45fad81 100644 --- a/lua/telescope/mappings.lua +++ b/lua/telescope/mappings.lua @@ -112,6 +112,11 @@ --- map("i", "asdf", function(_prompt_bufnr) --- print "You typed asdf" --- end) +--- +--- map({"i", "n"}, "<C-r>", function(_prompt_bufnr) +--- print "You typed <C-r>" +--- end) +--- --- -- needs to return true if you want to map default_mappings and --- -- false if not --- return true @@ -284,12 +289,18 @@ end mappings.apply_keymap = function(prompt_bufnr, attach_mappings, buffer_keymap) local applied_mappings = { n = {}, i = {} } - local map = function(mode, key_bind, key_func, opts) - mode = string.lower(mode) - local key_bind_internal = a.nvim_replace_termcodes(key_bind, true, true, true) - applied_mappings[mode][key_bind_internal] = true + local map = function(modes, key_bind, key_func, opts) + if type(modes) == "string" then + modes = { modes } + end + + for _, mode in pairs(modes) do + mode = string.lower(mode) + local key_bind_internal = a.nvim_replace_termcodes(key_bind, true, true, true) + applied_mappings[mode][key_bind_internal] = true - telescope_map(prompt_bufnr, mode, key_bind, key_func, opts) + telescope_map(prompt_bufnr, mode, key_bind, key_func, opts) + end end if attach_mappings then |
