diff --git a/doc/telescope.txt b/doc/telescope.txt index 26638ca..5c49f9d 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -538,6 +538,16 @@ telescope.setup({opts}) *telescope.setup()* ..., ["jj"] = { "", type = "command" }, ["kk"] = { "echo \"Hello, World!\"", type = "command" },) + ..., + + You can also add additional options for mappings of any type + ("action" and "command"). For example: + + ..., + [""] = { + action = actions.move_selection_next, + opts = { nowait = true, silent = true } + }, ..., diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index bf8c211..26f5845 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -690,6 +690,16 @@ append( ["jj"] = { "", type = "command" }, ["kk"] = { "echo \"Hello, World!\"", type = "command" },) ..., + + You can also add additional options for mappings of any type + ("action" and "command"). For example: + + ..., + [""] = { + action = actions.move_selection_next, + opts = { nowait = true, silent = true } + }, + ..., ]] ) diff --git a/lua/telescope/mappings.lua b/lua/telescope/mappings.lua index 487891c..bbb6d48 100644 --- a/lua/telescope/mappings.lua +++ b/lua/telescope/mappings.lua @@ -172,6 +172,16 @@ local telescope_map = function(prompt_bufnr, mode, key_bind, key_func, opts) a.nvim_buf_set_keymap(prompt_bufnr, mode, key_bind, map_string, opts) end +local extract_keymap_opts = function(key_func) + if type(key_func) == "table" and key_func.opts ~= nil then + -- we can't clear this because key_func could be a table from the config. + -- If we clear it the table ref would lose opts after the first bind + -- We need to copy it so noremap and silent won't be part of the table ref after the first bind + return vim.deepcopy(key_func.opts) + end + return {} +end + mappings.apply_keymap = function(prompt_bufnr, attach_mappings, buffer_keymap) local applied_mappings = { n = {}, i = {} } @@ -205,7 +215,7 @@ mappings.apply_keymap = function(prompt_bufnr, attach_mappings, buffer_keymap) local key_bind_internal = a.nvim_replace_termcodes(key_bind, true, true, true) if not applied_mappings[mode][key_bind_internal] then applied_mappings[mode][key_bind_internal] = true - telescope_map(prompt_bufnr, mode, key_bind, key_func) + telescope_map(prompt_bufnr, mode, key_bind, key_func, extract_keymap_opts(key_func)) end end end @@ -218,7 +228,7 @@ mappings.apply_keymap = function(prompt_bufnr, attach_mappings, buffer_keymap) local key_bind_internal = a.nvim_replace_termcodes(key_bind, true, true, true) if not applied_mappings[mode][key_bind_internal] then applied_mappings[mode][key_bind_internal] = true - telescope_map(prompt_bufnr, mode, key_bind, key_func) + telescope_map(prompt_bufnr, mode, key_bind, key_func, extract_keymap_opts(key_func)) end end end