From c2c8a96161b8723f540830e7cb969ebe3b1dc328 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 7 Dec 2024 18:53:28 +0800 Subject: [PATCH] fix(cmp): fix nvim-cmp mapping close https://github.com/SpaceVim/SpaceVim/issues/4929 --- autoload/SpaceVim/layers/autocomplete.vim | 3 +++ lua/config/nvim-cmp.lua | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/autoload/SpaceVim/layers/autocomplete.vim b/autoload/SpaceVim/layers/autocomplete.vim index 7c4235b69..96fe8f6e5 100644 --- a/autoload/SpaceVim/layers/autocomplete.vim +++ b/autoload/SpaceVim/layers/autocomplete.vim @@ -322,6 +322,9 @@ function! SpaceVim#layers#autocomplete#config() abort endif "mapping + " + " 如果使用 nvim-cmp 作为补全引擎,那么 Tab 以及 Enter 快捷键的映射是在 + " ./lua/config/nvim-cmp.lua 内设置。 if s:tab_key_behavior ==# 'smart' if has('patch-7.4.774') imap SpaceVim#mapping#tab() diff --git a/lua/config/nvim-cmp.lua b/lua/config/nvim-cmp.lua index e3fb9a24b..2f11b1160 100644 --- a/lua/config/nvim-cmp.lua +++ b/lua/config/nvim-cmp.lua @@ -43,7 +43,12 @@ end local function enter(f) -- {{{ if copt.auto_completion_return_key_behavior == 'complete' then - cmp.mapping.confirm({ select = false }) + if cmp.visible() then + cmp.mapping.confirm({ select = false }) + return cmp.close() + else + pcall(f) + end elseif copt.auto_completion_return_key_behavior == 'smart' then expand_snippet(nil) if cmp.visible() then