From e384594deee2f7be225cb89dbcb72d9b6482fde8 Mon Sep 17 00:00:00 2001 From: Liam Dyer Date: Tue, 12 Nov 2024 13:25:31 -0500 Subject: [PATCH] feat: allow disabling keymap by passing an empty table --- lua/blink/cmp/keymap.lua | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lua/blink/cmp/keymap.lua b/lua/blink/cmp/keymap.lua index d644fcf1..994b68ab 100644 --- a/lua/blink/cmp/keymap.lua +++ b/lua/blink/cmp/keymap.lua @@ -146,22 +146,24 @@ function keymap.apply_keymap_to_current_buffer(keys_to_commands) -- insert mode: uses both snippet and insert commands for key, commands in pairs(keys_to_commands) do - keymap.set('i', key, function() - for _, command in ipairs(commands) do - -- special case for fallback - if command == 'fallback' then - return keymap.run_non_blink_keymap('i', key) - - -- run user defined functions - elseif type(command) == 'function' then - if command(require('blink.cmp')) then return end - - -- otherwise, run the built-in command - elseif require('blink.cmp')[command]() then - return + if #commands > 0 then + keymap.set('i', key, function() + for _, command in ipairs(commands) do + -- special case for fallback + if command == 'fallback' then + return keymap.run_non_blink_keymap('i', key) + + -- run user defined functions + elseif type(command) == 'function' then + if command(require('blink.cmp')) then return end + + -- otherwise, run the built-in command + elseif require('blink.cmp')[command]() then + return + end end - end - end) + end) + end end -- snippet mode @@ -171,7 +173,7 @@ function keymap.apply_keymap_to_current_buffer(keys_to_commands) if vim.tbl_contains(snippet_commands, command) then has_snippet_command = true end end - if has_snippet_command then + if has_snippet_command and #commands > 0 then keymap.set('s', key, function() for _, command in ipairs(keys_to_commands[key] or {}) do -- special case for fallback