-
I have been playing around with the virtual text on choice nodes, and I would like to be able to remove the virtual text when I leave insert mode. I am hoping to use this in conjunction with #258 (I would love a setting to toggle this somehow, but the workaround works) to effectively remove all traces of the snippet when I enter normal mode. To accomplish this, my ideas so far are to somehow trigger the events.leave event within the leave_snippet autocommand described in #258, example below: leave_snippet = function()
if ... then
ls.get_current_node():leave() -- Not real code, but the idea of what I want to do
ls.unlink_current()
end
end
autocmd * ModeChanged "lua leave_snippet()" Or, to allow a callback within the node_with_virtual_text on ModeChanged: ...
callbacks = {
[1] = {
...
["ModeChanged"] = function(nd)
<remove virtual text>
end
}} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Using vim.api.nvim_create_autocmd("InsertLeave", {
callback = function()
local active_node = ls.session.current_nodes[1]
if not active_node then
return
end
local snippet = active_node.parent.snippet
snippet:set_ext_opts("snippet_passive")
snippet.mark:update_opts(snippet.ext_opts.snippet_passive)
end
})
vim.api.nvim_create_autocmd("InsertEnter", {
callback = function()
local active_node = ls.session.current_nodes[1]
if not active_node then
return
end
local snippet = active_node.parent.snippet
snippet:set_ext_opts("passive")
local nodes_between = require("luasnip.nodes.util").get_nodes_between(snippet, active_node.absolute_position)
for _, node in ipairs(nodes_between) do
node.mark:update_opts(node.ext_opts.active)
end
end
}) (I did get some errors initially, but can't reproduce them now. If you do, please post them) |
Beta Was this translation helpful? Give feedback.
Using
node:leave()
should do it, but it might have side-effects (for example, if the content of the left node should be modified on leave)Here's something that works, but consider it "unsupported" (I'll include something like it as
ls.hide/show_extmarks
in some time, I'm not sure yet if a simplehide/show_extmarks
really is what we want here (as opposed to some abstraction one could do more with))