Skip to content

Commit

Permalink
feat: allow disabling keymap by passing an empty table
Browse files Browse the repository at this point in the history
  • Loading branch information
Saghen committed Nov 12, 2024
1 parent a2f6cfb commit e384594
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions lua/blink/cmp/keymap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e384594

Please sign in to comment.