nvim-cmp icon indicating copy to clipboard operation
nvim-cmp copied to clipboard

[Feature Request] Create undo point before completion

Open statiolake opened this issue 2 years ago • 1 comments

Currently nvim-cmp creates undo point before snippet expansion:

https://github.com/hrsh7th/nvim-cmp/blob/dd6e4d96f9e376c87302fa5414556aa6269bf997/lua/cmp/core.lua#L364-L366

... but I'd be happy if I can go back to the last state just before confirmation in one step, like VSCode. Following GIF describes what I want. (I have key mapping to undo in insert mode.)

Animation

In this case, current nvim-cmp undos only snippet expansion, I'll have function after undo. Then I need to remove extra characters to get what I wanted (functor). This GIF is taken from my fork (https://github.com/statiolake/nvim-cmp/commit/77eeb2b10ce0c9967d2492381cf25371f0a5ce65). Just changed ordering. It works, at least the above example, but I'm not sure this correctly fixes the problem.

I can create undo point before confirming completion without modifying nvim-cmp but then I need to undo twice to get the original state (first for cancelling expansion created by nvim-cmp, second to restore the original input).

Also note that I'm using custom completion view and SelectBehavior.Select. With native completion menu or SelectBehavior.Insert, words are inserted soon after selecting, so undo can't restore the initial state if user explicitly selected some entry. I don't have any idea what should be done in that case. (However, if the user explicitly chose to insert it, I don't think it is likely to be a mistake that they would want to undo, so I don't think it is really a big issue.)

Thank you for this awesome plugin!

statiolake avatar Mar 28 '22 19:03 statiolake

This seems to be a nice feature to have IMO

c3n21 avatar Sep 15 '22 14:09 c3n21