Skip to content

Commit e384594

Browse files
committed
feat: allow disabling keymap by passing an empty table
1 parent a2f6cfb commit e384594

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

lua/blink/cmp/keymap.lua

+18-16
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,24 @@ function keymap.apply_keymap_to_current_buffer(keys_to_commands)
146146

147147
-- insert mode: uses both snippet and insert commands
148148
for key, commands in pairs(keys_to_commands) do
149-
keymap.set('i', key, function()
150-
for _, command in ipairs(commands) do
151-
-- special case for fallback
152-
if command == 'fallback' then
153-
return keymap.run_non_blink_keymap('i', key)
154-
155-
-- run user defined functions
156-
elseif type(command) == 'function' then
157-
if command(require('blink.cmp')) then return end
158-
159-
-- otherwise, run the built-in command
160-
elseif require('blink.cmp')[command]() then
161-
return
149+
if #commands > 0 then
150+
keymap.set('i', key, function()
151+
for _, command in ipairs(commands) do
152+
-- special case for fallback
153+
if command == 'fallback' then
154+
return keymap.run_non_blink_keymap('i', key)
155+
156+
-- run user defined functions
157+
elseif type(command) == 'function' then
158+
if command(require('blink.cmp')) then return end
159+
160+
-- otherwise, run the built-in command
161+
elseif require('blink.cmp')[command]() then
162+
return
163+
end
162164
end
163-
end
164-
end)
165+
end)
166+
end
165167
end
166168

167169
-- snippet mode
@@ -171,7 +173,7 @@ function keymap.apply_keymap_to_current_buffer(keys_to_commands)
171173
if vim.tbl_contains(snippet_commands, command) then has_snippet_command = true end
172174
end
173175

174-
if has_snippet_command then
176+
if has_snippet_command and #commands > 0 then
175177
keymap.set('s', key, function()
176178
for _, command in ipairs(keys_to_commands[key] or {}) do
177179
-- special case for fallback

0 commit comments

Comments
 (0)