diff options
| author | Waldson PatrĂcio <waldsonpatricio@gmail.com> | 2022-03-20 17:34:07 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-20 21:34:07 +0100 |
| commit | 1a72a92b641e1dab42036c07e2571b43c55bfaa1 (patch) | |
| tree | 417a6002a86b0ca9764e1cfc306fd39c2218a67c /lua/telescope/mappings.lua | |
| parent | 6a43634f5f492113fd0bdec225d936a17b9ecbf2 (diff) | |
feat: enable individual options for mappings (#890)
Co-authored-by: Simon Hauser <Simon-Hauser@outlook.de>
Diffstat (limited to 'lua/telescope/mappings.lua')
| -rw-r--r-- | lua/telescope/mappings.lua | 14 |
1 files changed, 12 insertions, 2 deletions
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 |
