From d541e0d6e00a0d89f21e1b0e6fe92c736ac0f83b Mon Sep 17 00:00:00 2001 From: ADoyle Date: Mon, 7 Nov 2022 00:42:29 +0800 Subject: feat: the parameter "map" of attach_mappings can be list of modes to create mapping on multiple modes (#2220) --- lua/telescope/mappings.lua | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'lua/telescope/mappings.lua') 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"}, "", function(_prompt_bufnr) +--- print "You typed " +--- 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 -- cgit v1.2.3