Repository navigation
Toggle Snacks.image #2962
|
I try to add a toggle to Snacks.images. I managed to toggle the enabled option, however, already rendered images from open buffers are not cleared. Even when open and close it again. I could not find any clear method in the Thanks a lot for any help :) local image_toggle = Snacks.toggle.new({
id = "snacks_image",
name = "Snacks Image Preview",
get = function()
return Snacks.image and Snacks.image.config.enabled == true
end,
set = function(state)
Snacks.image.config.enabled = state
Snacks.image.config.doc.enabled = state
end,
})
map("n", "<leader>uP", function()
image_toggle:toggle()
end, { desc = "Toggle Snacks Image" }) |
Replies: 2 comments 2 replies
|
There is a cleanup method one level below Snacks.image.doc.hover_close()
Snacks.image.placement.clean() -- all buffers; pass a buffer number to limit it
One caveat for your toggle: changing For a robust runtime toggle the module would also need to suspend the existing inline/hover updates and restore them when enabled. That explains why mutating the setup options alone doesn't clear your open buffers, and why simply reopening a window may not reset it. |
|
Hi, just wanted to mention this is also discussed in #1739 with a first external implementation shared in this comment (suffering from the same issues discussed above) and a solution that hacks the snacks.image code directly in another comment |
There is a cleanup method one level below
Snacks.image:placement.clean()closes the tracked placements, including their terminal graphics and extmarks. It is also what Snacks uses when buffers are deleted and on exit.One caveat for your toggle: changing
config.enabledis not a full teardown.doc.attach()checks that flag when attaching, but an already attachedinlinerenderer has its own update lifecycle and can create placements again. So the two calls above clear what's currently displayed; they are not, by themselves, a complete persistent disable/enable implementation.For …