Merge pull request #316 from diniamo/fix-autopairs-cr

modules/nvim-cmp: add edge case for autopairs in cr mapping
This commit is contained in:
raf 2024-06-25 09:09:04 +00:00 committed by GitHub
commit 688a457a3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 10 deletions

View file

@ -4,7 +4,6 @@
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.strings) optionalString;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;
@ -14,7 +13,7 @@ in {
vim.startPlugins = ["nvim-autopairs"];
vim.luaConfigRC.autopairs = entryAnywhere ''
require("nvim-autopairs").setup{}
require("nvim-autopairs").setup({ map_cr = ${toLuaObject (!config.vim.autocomplete.enable)} })
'';
};
}

View file

@ -61,12 +61,16 @@ in {
(mkSetLuaBinding mappings.complete ''
require('cmp').complete
'')
(mkSetLuaBinding mappings.confirm ''
(let
defaultKeys =
if config.vim.autopairs.enable
then "require('nvim-autopairs').autopairs_cr()"
else "vim.api.nvim_replace_termcodes(${toJSON mappings.confirm.value}, true, false, true)";
in
mkSetLuaBinding mappings.confirm ''
function()
if not require('cmp').confirm({ select = true }) then
local termcode = vim.api.nvim_replace_termcodes(${toJSON mappings.confirm.value}, true, false, true)
vim.fn.feedkeys(termcode, 'n')
vim.fn.feedkeys(${defaultKeys}, 'n')
end
end
'')