@@ -33,6 +33,7 @@ M.triggerCompletion = function()
33
33
source .triggerCompletion (true , manager )
34
34
end
35
35
36
+
36
37
M .completionToggle = function ()
37
38
local enable = api .nvim_call_function (' completion#get_buffer_variable' , {' completion_enable' })
38
39
if enable == nil then
@@ -110,6 +111,17 @@ local function hasConfirmedCompletion()
110
111
end
111
112
end
112
113
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
113
125
---- --------------------------------------------------------------------
114
126
-- autocommands --
115
127
---- --------------------------------------------------------------------
@@ -213,11 +225,19 @@ M.on_attach = function(option)
213
225
api .nvim_command (" autocmd InsertCharPre <buffer> lua require'completion'.on_InsertCharPre()" )
214
226
api .nvim_command (" autocmd CompleteDone <buffer> lua require'completion'.on_CompleteDone()" )
215
227
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
221
241
end
222
242
-- overwrite vsnip_integ autocmd since we handle it on ourself in confirmCompletion
223
243
if vim .fn .exists (" #vsnip_integ" ) then
0 commit comments