@@ -33,6 +33,7 @@ M.triggerCompletion = function()
3333 source .triggerCompletion (true , manager )
3434end
3535
36+
3637M .completionToggle = function ()
3738 local enable = api .nvim_call_function (' completion#get_buffer_variable' , {' completion_enable' })
3839 if enable == nil then
@@ -110,6 +111,17 @@ local function hasConfirmedCompletion()
110111 end
111112end
112113
114+ -- make sure we didn't overwrite user defined mapping
115+ local function checkMapping (map , key )
116+ for _ , m in ipairs (map ) do
117+ if api .nvim_replace_termcodes (m .lhs , true , false , true ) == api .nvim_replace_termcodes (key , true , false , true ) then
118+ if not m .rhs :find (" completion_confirm_completion" ) then
119+ return false
120+ end
121+ end
122+ end
123+ return true
124+ end
113125---- --------------------------------------------------------------------
114126-- autocommands --
115127---- --------------------------------------------------------------------
@@ -213,11 +225,19 @@ M.on_attach = function(option)
213225 api .nvim_command (" autocmd InsertCharPre <buffer> lua require'completion'.on_InsertCharPre()" )
214226 api .nvim_command (" autocmd CompleteDone <buffer> lua require'completion'.on_CompleteDone()" )
215227 api .nvim_command (" augroup end" )
216- if string.len (opt .get_option (' confirm_key' )) ~= 0 then
217- api .nvim_buf_set_keymap (0 , ' i' , opt .get_option (' confirm_key' ),
218- ' pumvisible() ? complete_info()["selected"] != "-1" ? "\\ <Plug>(completion_confirm_completion)" :' ..
219- ' "\\ <c-e>\\ <CR>" : "\\ <CR>"' ,
220- {silent = false , noremap = false , expr = true })
228+ local confirm_key = opt .get_option (' confirm_key' )
229+ if string.len (confirm_key ) ~= 0 then
230+ if checkMapping (api .nvim_buf_get_keymap (0 , " i" ), confirm_key ) and
231+ (manager .checkGlobalMapping or checkMapping (api .nvim_get_keymap (" i" ), confirm_key )) then
232+ manager .checkGlobalMapping = true
233+ api .nvim_buf_set_keymap (0 , ' i' , confirm_key , ' <Plug>(completion_confirm_completion)' ,
234+ {silent = false , noremap = false })
235+ else
236+ api .nvim_err_writeln (string.format (
237+ " completion-nvim: mapping conflict! you've already mapped your confirm key to something else in insert mode. " ..
238+ " Consider changing g:completion_confirm_key"
239+ ))
240+ end
221241 end
222242 -- overwrite vsnip_integ autocmd since we handle it on ourself in confirmCompletion
223243 if vim .fn .exists (" #vsnip_integ" ) then
0 commit comments