mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-24 01:38:54 +02:00
feat(cmp): create undo point right before confirming a completion
This commit is contained in:
parent
96aa4b8877
commit
673975ebbe
2 changed files with 17 additions and 1 deletions
|
@ -36,7 +36,15 @@ return {
|
||||||
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
||||||
["<C-Space>"] = cmp.mapping.complete(),
|
["<C-Space>"] = cmp.mapping.complete(),
|
||||||
["<C-e>"] = cmp.mapping.abort(),
|
["<C-e>"] = cmp.mapping.abort(),
|
||||||
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
["<CR>"] = function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
LazyVim.create_undo()
|
||||||
|
if cmp.confirm({ select = true }) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return fallback()
|
||||||
|
end,
|
||||||
["<S-CR>"] = cmp.mapping.confirm({
|
["<S-CR>"] = cmp.mapping.confirm({
|
||||||
behavior = cmp.ConfirmBehavior.Replace,
|
behavior = cmp.ConfirmBehavior.Replace,
|
||||||
select = true,
|
select = true,
|
||||||
|
|
|
@ -190,4 +190,12 @@ function M.dedup(list)
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M.CREATE_UNDO = vim.api.nvim_replace_termcodes("<c-G>u", true, true, true)
|
||||||
|
function M.create_undo()
|
||||||
|
if vim.api.nvim_get_mode().mode == "i" then
|
||||||
|
dd("undo")
|
||||||
|
vim.api.nvim_feedkeys(M.CREATE_UNDO, "n", false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue