Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Commit

Permalink
fix: avoid overwrting user defined mapping
Browse files Browse the repository at this point in the history
fix some stuff

fix
  • Loading branch information
haorenW1025 committed Jul 22, 2020
1 parent 8aecb23 commit 432963d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
27 changes: 22 additions & 5 deletions lua/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ local function hasConfirmedCompletion()
end
end

-- make sure we didn't overwrite user defined mapping
local function checkMapping(map, key)
for _, m in ipairs(map) do
if api.nvim_replace_termcodes(m.lhs, true, false, true) == api.nvim_replace_termcodes(key, true, false, true) then
print(api.nvim_replace_termcodes(m.lhs, true, false, true), vim.inspect(m))
return false
end
end
return true
end
------------------------------------------------------------------------
-- autocommands --
------------------------------------------------------------------------
Expand Down Expand Up @@ -213,11 +223,18 @@ M.on_attach = function(option)
api.nvim_command("autocmd InsertCharPre <buffer> lua require'completion'.on_InsertCharPre()")
api.nvim_command("autocmd CompleteDone <buffer> lua require'completion'.on_CompleteDone()")
api.nvim_command("augroup end")
if string.len(opt.get_option('confirm_key')) ~= 0 then
api.nvim_buf_set_keymap(0, 'i', opt.get_option('confirm_key'),
'pumvisible() ? complete_info()["selected"] != "-1" ? "\\<Plug>(completion_confirm_completion)" :'..
' "\\<c-e>\\<CR>" : "\\<CR>"',
{silent=false, noremap=false, expr=true})
local confirm_key = opt.get_option('confirm_key')
if string.len(confirm_key) ~= 0 then
if checkMapping(api.nvim_buf_get_keymap(0, "i"), confirm_key) and
(manager.checkGlobalMapping or checkMapping(api.nvim_get_keymap("i"), confirm_key)) then
manager.checkGlobalMapping = true
api.nvim_buf_set_keymap(0, 'i', confirm_key,
'pumvisible() ? complete_info()["selected"] != "-1" ? "\\<Plug>(completion_confirm_completion)" :'..
' "\\<c-e>\\<CR>" : "\\<CR>"',
{silent=false, noremap=false, expr=true})
else
api.nvim_err_writeln("completion-nvim: mapping conflict, please consider changing g:completion_confirm_key")
end
end
-- overwrite vsnip_integ autocmd since we handle it on ourself in confirmCompletion
if vim.fn.exists("#vsnip_integ") then
Expand Down
1 change: 1 addition & 0 deletions lua/completion/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ manager = {
confirmedCompletion = false, -- flag for manual confirmation of completion
forceCompletion = false, -- flag for forced manual completion/source change
chainIndex = 1, -- current index in loaded chain
checkGlobalMapping = false -- indication of global mapping is checked or not
}

-- reset manager
Expand Down

0 comments on commit 432963d

Please sign in to comment.