hsnips icon indicating copy to clipboard operation
hsnips copied to clipboard

I can not undo the snippet expansion

Open yfzhao20 opened this issue 3 years ago • 3 comments

Related to issue 27. I can not undo that!

snippet ( "()" iA
($1)$0
endsnippet

5jfgfd

snippet `(?<=[a-zA-z])([0-9])` "d" iA
_``rv=m[1]``
endsnippet

5jfgfd

yfzhao20 avatar Nov 25 '21 08:11 yfzhao20

Thanks for the report, the issue on both those examples is that the undo action is inserting exactly 1 character, and there is no way that I know of to tell the difference between an undo action and a user keypress. For instance, in your first example, if you selected the text () and typed (, the edit event we receive would be exactly the same as the event we receive from the undo action.

I'll try to think of a solution for this, but nothing is coming to mind right now.

draivin avatar Dec 02 '21 22:12 draivin

As a sidenote, in the second example you can fix this by actually matching the letters and numbers, instead of using a lookbehind, so it would look something like:

snippet `([a-zA-z])([0-9])` "d" iA
``rv=m[1]``_``rv=m[2]``
endsnippet

draivin avatar Dec 02 '21 22:12 draivin