From 5c793ef591018317bccf974771c6251b9b1f8adc Mon Sep 17 00:00:00 2001 From: CharlesChiuGit Date: Sun, 30 Jun 2024 11:49:05 +0000 Subject: [PATCH] feat(cmp): make `` safer --- lua/modules/configs/completion/cmp.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lua/modules/configs/completion/cmp.lua b/lua/modules/configs/completion/cmp.lua index 0c84b0199..d9676a107 100644 --- a/lua/modules/configs/completion/cmp.lua +++ b/lua/modules/configs/completion/cmp.lua @@ -127,7 +127,6 @@ return function() }, -- You can set mappings if you want mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.confirm({ select = false, behavior = cmp.ConfirmBehavior.Replace }), [""] = cmp.mapping.select_prev_item(), [""] = cmp.mapping.select_next_item(), [""] = cmp.mapping.scroll_docs(-4), @@ -151,6 +150,17 @@ return function() fallback() end end, { "i", "s" }), + [""] = cmp.mapping({ + i = function(fallback) + if cmp.visible() and cmp.get_active_entry() then + cmp.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = false }) + else + fallback() + end + end, + s = cmp.mapping.confirm({ select = true }), + c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = true }), + }), }), snippet = { expand = function(args)