Skip to content

Commit ae5a4ce

Browse files
committed
fix: fallback not working for built-in mappings
Closes #489
1 parent 68ba8ae commit ae5a4ce

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lua/blink/cmp/keymap/fallback.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ end
2929
--- @param key string
3030
--- @return vim.api.keyset.keymap?
3131
function fallback.get_non_blink_buffer_mapping_for_key(mode, key)
32-
local ret = vim.fn.maparg(key, mode, false, true) --[[@as vim.api.keyset.keymap]]
33-
if ret and ret.buffer == 0 then return end
34-
if ret and ret.desc and ret.desc == 'blink.cmp' then return end
35-
return ret.lhs ~= nil and ret or nil
32+
local normalized_key = vim.api.nvim_replace_termcodes(key, true, true, true)
33+
34+
local buffer_mappings = vim.api.nvim_buf_get_keymap(0, mode)
35+
36+
for _, mapping in ipairs(buffer_mappings) do
37+
local mapping_key = vim.api.nvim_replace_termcodes(mapping.lhs, true, true, true)
38+
if mapping_key == normalized_key and mapping.desc ~= 'blink.cmp' then return mapping end
39+
end
3640
end
3741

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

0 commit comments

Comments
 (0)