ultisnips
ultisnips copied to clipboard
Post‐jump actions discard changes to the cursor position when jumping to a placeholder with default text
Expected behavior: When a jump is issued to a placeholder with a default text, the default text is selected (SELECT mode). If a post‐jump action is defined, it will be run before the selection happens. The action (Python code) can modify the contents of the current line, in which case it should update the cursor position accordingly. In particular, the following code:
snip.cursor.set(snip.cursor[0], snip.cursor[1] + 3)
should result in the selected region being found three columns further than where it would have been otherwise.
Actual behavior:
Any change to snip.cursor
, and even to vim.current.window.cursor
, is discarded. This happens because the coordinates of the selection are hard‐coded before the action is run, as can be seen here.
Steps to reproduce
-
Save the snippets provided below in
~/.vim/UltiSnips/all.snippets
. -
Open Vim with a new buffer.
-
Type (assuming default key bindings): a.
itestnodef<Tab><C-j>
(the initiali
to enter INSERT mode); you get the correct result:prepended[][] ↑ INSERT mode
b.
itestdef<Tab><C-j>
(the initiali
to enter INSERT mode); you get the buggy result (“default” should be selected):prepended[][default] ↑↑↑↑↑↑↑ SELECT mode
global !p
def test_snippet():
snip.buffer[snip.cursor[0]] = "prepended" + snip.buffer[snip.cursor[0]]
snip.cursor.set(snip.cursor[0], snip.cursor[1] + 9)
endglobal
post_jump "if snip.tabstop == 0: test_snippet()"
snippet testnodef
[${1}][${0}]
endsnippet
post_jump "if snip.tabstop == 0: test_snippet()"
snippet testdef
[${1}][${0:default}]
endsnippet
- Operating System: Archlinux, kernel 4.17.2, x86_64
- Vim Version: 8.1 (2018 May 17), included patches: 1-22
- UltiSnips Version: git revision 6fdc3647f72e0a1f321ea6bd092ecd01f7c187ba
- Python inside Vim: 2.7.15 / 3.6.5
Terrific bug report, thanks so much!
Reproduces at 4f4d500e21b307894490b24413d663c1c124307f.