Recreating UltiSnip's VISUAL #1100
-
I thought about this a long time, but could not figure it out. I recreated local function insert_wrap(_, snip) -- Emulate Ultisnips' '${1:${VISUAL}}'
local raw = snip.env.LS_SELECT_RAW
if #raw == 0 then -- Insert text if no selection
return sn(nil, i(1))
else -- Else insert selection
return sn(nil, t(raw))
end
end
return {}, {
s({
trig = 'mt',
name = 'inline math mode'
}, {
t('$'), i(1), t('$')
}),
s({
trig = "(",
dscr = "parenthesis",
wordTrig = false
}, {
t('('), d(1, insert_wrap), t(')')
}),
s({
trig = '_',
name = 'subscript',
wordTrig = false,
}, {
t('_'),
m(1, '^.$', '', '{'), i(1), m(1, '^.$', '', '}')
}),
} The idea is to make a subscript command in Latex, but only wrap the input in braces if the input is precisely one character. Now, if I type But if I type Could someone explain to me why this is happening? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey, nice catch, that's a bug! |
Beta Was this translation helpful? Give feedback.
Hey, nice catch, that's a bug!
The issue was that the extmark that marks the region of the i(1) was not adjusted correctly during expansion of the
()
-snippet, and since it had end-rgrav true, it received all the text inserted into the()
.I've fixed this (straightforward with your example/MWE, thank you!), and it should all work correctly on
master
.(this bug only occurs if the new snippet is expanded inside another snippet, immediately (so no text at all between them) behind another insertNode, I guess that's why it only popped up so late :D )