diff options
| author | daangoossens22 <62295482+daangoossens22@users.noreply.github.com> | 2022-01-28 16:36:42 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-28 16:36:42 +0100 |
| commit | 3a3c9a3c8ba3fb14121ef5c50a87173dcb969416 (patch) | |
| tree | 387005c35a1ff425ec7481eca12b9afdda05ec9f /lua/telescope/builtin/internal.lua | |
| parent | 6c275e2f6ae8c68c8bf07ca48ea14af4ced2f803 (diff) | |
feat (keymaps): add configuration options (#1703)
Diffstat (limited to 'lua/telescope/builtin/internal.lua')
| -rw-r--r-- | lua/telescope/builtin/internal.lua | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index 4765e60..8e1c9c4 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -952,18 +952,28 @@ end -- TODO: make filtering include the mapping and the action internal.keymaps = function(opts) - local modes = { "n", "i", "c" } - local keymaps_table = {} + opts.modes = vim.F.if_nil(opts.modes, { "n", "i", "c", "x" }) + opts.show_plug = vim.F.if_nil(opts.show_plug, true) + local keymap_encountered = {} -- used to make sure no duplicates are inserted into keymaps_table + local keymaps_table = {} local max_len_lhs = 0 - for _, mode in pairs(modes) do - local function extract_keymaps(keymaps) - for _, keymap in pairs(keymaps) do - table.insert(keymaps_table, keymap) - max_len_lhs = math.max(max_len_lhs, string.len(keymap.lhs or "")) + + -- helper function to populate keymaps_table and determine max_len_lhs + local function extract_keymaps(keymaps) + for _, keymap in pairs(keymaps) do + local keymap_key = keymap.buffer .. keymap.mode .. keymap.lhs -- should be distinct for every keymap + if not keymap_encountered[keymap_key] then + keymap_encountered[keymap_key] = true + if opts.show_plug or not string.find(keymap.lhs, "<Plug>") then + table.insert(keymaps_table, keymap) + max_len_lhs = math.max(max_len_lhs, #utils.display_termcodes(keymap.lhs)) + end end end + end + for _, mode in pairs(opts.modes) do local global = vim.api.nvim_get_keymap(mode) local buf_local = vim.api.nvim_buf_get_keymap(0, mode) extract_keymaps(global) |
