@@ -110,6 +110,16 @@ local function hasConfirmedCompletion()
110
110
end
111
111
end
112
112
113
+ -- make sure we didn't overwrite user defined mapping
114
+ local function checkMapping (map , key )
115
+ for _ , m in ipairs (map ) do
116
+ if api .nvim_replace_termcodes (m .lhs , true , false , true ) == api .nvim_replace_termcodes (key , true , false , true ) then
117
+ print (api .nvim_replace_termcodes (m .lhs , true , false , true ), vim .inspect (m ))
118
+ return false
119
+ end
120
+ end
121
+ return true
122
+ end
113
123
---- --------------------------------------------------------------------
114
124
-- autocommands --
115
125
---- --------------------------------------------------------------------
@@ -213,11 +223,18 @@ M.on_attach = function(option)
213
223
api .nvim_command (" autocmd InsertCharPre <buffer> lua require'completion'.on_InsertCharPre()" )
214
224
api .nvim_command (" autocmd CompleteDone <buffer> lua require'completion'.on_CompleteDone()" )
215
225
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 })
226
+ local confirm_key = opt .get_option (' confirm_key' )
227
+ if string.len (confirm_key ) ~= 0 then
228
+ if checkMapping (api .nvim_buf_get_keymap (0 , " i" ), confirm_key ) and
229
+ (manager .checkGlobalMapping or checkMapping (api .nvim_get_keymap (" i" ), confirm_key )) then
230
+ manager .checkGlobalMapping = true
231
+ api .nvim_buf_set_keymap (0 , ' i' , confirm_key ,
232
+ ' pumvisible() ? complete_info()["selected"] != "-1" ? "\\ <Plug>(completion_confirm_completion)" :' ..
233
+ ' "\\ <c-e>\\ <CR>" : "\\ <CR>"' ,
234
+ {silent = false , noremap = false , expr = true })
235
+ else
236
+ api .nvim_err_writeln (" completion-nvim: mapping conflict, please consider changing g:completion_confirm_key" )
237
+ end
221
238
end
222
239
-- overwrite vsnip_integ autocmd since we handle it on ourself in confirmCompletion
223
240
if vim .fn .exists (" #vsnip_integ" ) then
0 commit comments