Skip to content

Commit

Permalink
fix: fallback not working for built-in mappings
Browse files Browse the repository at this point in the history
Closes #489
  • Loading branch information
Saghen committed Dec 11, 2024
1 parent 68ba8ae commit ae5a4ce
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lua/blink/cmp/keymap/fallback.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ end
--- @param key string
--- @return vim.api.keyset.keymap?
function fallback.get_non_blink_buffer_mapping_for_key(mode, key)
local ret = vim.fn.maparg(key, mode, false, true) --[[@as vim.api.keyset.keymap]]
if ret and ret.buffer == 0 then return end
if ret and ret.desc and ret.desc == 'blink.cmp' then return end
return ret.lhs ~= nil and ret or nil
local normalized_key = vim.api.nvim_replace_termcodes(key, true, true, true)

local buffer_mappings = vim.api.nvim_buf_get_keymap(0, mode)

for _, mapping in ipairs(buffer_mappings) do
local mapping_key = vim.api.nvim_replace_termcodes(mapping.lhs, true, true, true)
if mapping_key == normalized_key and mapping.desc ~= 'blink.cmp' then return mapping end
end
end

--- Returns a function that will run the first non blink.cmp keymap for the given mode and key
Expand All @@ -44,6 +48,7 @@ function fallback.wrap(mode, key)
return function()
local mapping = buffer_mapping or fallback.get_non_blink_global_mapping_for_key(mode, key)
if mapping then return fallback.run_non_blink_keymap(mapping, key) end
return vim.api.nvim_replace_termcodes(key, true, true, true)
end
end

Expand Down

0 comments on commit ae5a4ce

Please sign in to comment.