-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
buffer-local fallback mappings not triggered #482
Comments
Just checked the code and I see there's actually support for this. fyi, this is my blink keymap config: keymap = {
preset = "enter",
["<Tab>"] = {
LazyVim.cmp.map({ "snippet_forward", "ai_accept" }),
"fallback",
},
}, The fallback does not trigger for both |
I don't think this line can work, since the buffer-local keymap has been replaced by the blink one. https://github.com/Saghen/blink.cmp/blob/main/lua/blink/cmp/keymap/apply.lua#L21 |
Yeah, sounds like a bug, I didn't realize there can't be multiple buffer local mappings on a single key. For now, would it make sense to mark your UI with |
fyi: to get a mapping (local/global), it's much much faster to use |
I'll create a PR |
See my PR :) I've also changed the impl to use |
In my opinion, nvim-cmp's key mapping fallback mechanism is too complicated, so I don't recommend implementing it from scratch. Instead, you can consider returning an empty string from This seems like a cleaner way to achieve "key mapping for a specific context", similar to native completion key bindings. |
That's actually a great idea! |
However, would be great to have my PR merged already, since I would like to launch a bunch of new plugins today and the |
Looks like that empty string behavior is new neovim/neovim@b34e137. The whole keymap code gets reduced to just the following (very rough code :)), but we'll have to wait for the 0.11 release local keymap = {}
function keymap.setup()
local mappings = vim.deepcopy(require('blink.cmp.config').keymap)
-- Handle preset
if mappings.preset then
local preset_keymap = require('blink.cmp.keymap.presets').get(mappings.preset)
-- Remove 'preset' key from opts to prevent it from being treated as a keymap
mappings.preset = nil
-- Merge the preset keymap with the user-defined keymaps
-- User-defined keymaps overwrite the preset keymaps
mappings = vim.tbl_extend('force', preset_keymap, mappings)
end
local snippet_commands = { 'snippet_forward', 'snippet_backward' }
-- TODO: handle multiple keys like <C-g><C-o>
vim.on_key(function(original_key, key)
if not require('blink.cmp.config').enabled() then return original_key end
local mode = vim.api.nvim_get_mode().mode
if mode ~= 'i' and mode ~= 's' then return original_key end
for command_key, commands in pairs(mappings) do
if vim.api.nvim_replace_termcodes(command_key, true, true, true) == key then
for _, command in ipairs(commands) do
-- ignore snippet commands for insert mode
if vim.tbl_contains(snippet_commands, command) and mode == 'i' then goto continue end
-- special case for fallback, return the key so that neovim continues like normal
if command == 'fallback' then
return original_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
::continue::
end
end
end
return original_key
end)
end
return keymap |
blink.cmp/lua/blink/cmp/keymap/init.lua
Line 31 in b368f77
I'm working on a new plugin (better
vim.ui.input
) that opens a floating window and sets keymaps for both<tab>
and<cr>
.Blink overrides these buffer-local keymaps.
Is that the intended behavior?
I can't really control users to make sure they exclude the filetype to the blink
enabled
.Apart from that, in some cases completion is for sure useful.
Is there any way to trigger the existing keymap when overriding it in the buffer?
Or restoring the old keymaps when the menu closes?
The text was updated successfully, but these errors were encountered: