ultisnips icon indicating copy to clipboard operation
ultisnips copied to clipboard

`post_expand` & `post_jump` cause nested snippets cursor position/order error.

Open pilgrimlyieu opened this issue 1 year ago • 0 comments

Demo

Snippets Code
global !p

def test(snip):
	before = snip.buffer[snip.line][:snip.snippet_start[1]]
	after = snip.buffer[snip.line][snip.snippet_end[1]:]
	snip.buffer[snip.line] = ''
	snip.expand_anon(before + '[$1, $2]$0' + after)

endglobal

snippet t "Description" i
($1, $2)$0
endsnippet

snippet a "Description" i
[$1, $2]$0
endsnippet

post_expand "test(snip)"
snippet b "Description" i
endsnippet

post_jump "test(snip)"
snippet c "Description" i
endsnippet

Expected behavior:

Cursor can jump in right position in a right order like the first line in Demo.

Actual behavior:

post_expand can have correct cursor position. However, its cursor order is incorrect. Shown in the second line in Demo.

post_jump can have correct cursor order. However, its cursor position is incorrect and it will cause strange selection behavior as well. Shown in the third line in Demo.

Since the tabstops number is not sure, snippets using post action is more general. So I wonder that if there is a way to avoid this issue.

Steps to reproduce

  1. Create the above minimum snippets file
  2. Type as above

pilgrimlyieu avatar Jul 12 '22 09:07 pilgrimlyieu