ChoiceNode and default options #1426
|
Hi! I'm writing a snippet with two choice nodes with the same options and I'm wondering if there's a way to show different defaults. I can probably explain it better with a toy example local my_options = { t 'opt1', t 'opt2', t 'opt3' }
s('choices', {
t 'something ',
c(1, my_options), -- shows opt1, OK
t ' something ',
c(2, my_options), -- should show, e.g., opt2
}),For now, I've solved by changing the table c(2, my_options, {node_callbacks = {
[events.enter] = function(_, _)
require('luasnip').set_choice(2)
end,
},
})but I couldn't make it work. Thanks in advance! |
Replies: 1 comment 1 reply
|
local function from(n, choices)
local out = {}
for i = 1, #choices do
out[i] = choices[(n + i - 2) % #choices + 1]
end
return out
end
c(2, from(2, my_options))The |
choices[1]is always the initial one.init_nodesinchoiceNode.luahardcodesself.active_choice = self.choices[1], and there's no opt for it. Your rotation is the right call:The
entercallback can't get you there anyway. It fires mid-jump, before the node becomes current, andset_choicere-enters the same code path. Even if it landed, the buffer would still showopt1until you jump to that node.