From 0400df5931bb1dfa8fd4108a6bc5e54cda2cee15 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Date: Sun, 28 Jun 2026 20:35:50 +0200 Subject: [PATCH] fix(image.inline): keep placements when find_visible returns no images `find_visible` is treesitter-backed and intermittently returns zero images while the parser reparses a rapidly-changing buffer (e.g. streaming text into a markdown buffer holding an inline image), even though the image is still present. The empty result was treated as "all images gone", closing the placement; the next non-empty parse recreated it, so every edit closed and recreated the placement = visible flicker. Treat an empty result as inconclusive and keep existing placements, reconciling only when `find_visible` actually reports images. Tradeoff: going from N images to 0 defers closing the last placement until a later non-empty `find_visible`. --- lua/snacks/image/inline.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lua/snacks/image/inline.lua b/lua/snacks/image/inline.lua index 12a59ee6c..aa2586776 100644 --- a/lua/snacks/image/inline.lua +++ b/lua/snacks/image/inline.lua @@ -93,6 +93,13 @@ function M:update() return conceal end or conceal Snacks.image.doc.find_visible(self.buf, function(imgs) + -- `find_visible` is treesitter-backed and can return no images while the + -- parser reparses a rapidly-changing buffer, even when an image is still + -- present. Treating that as "all gone" closes and recreates placements on + -- the next parse, which flickers. Keep placements until it reports images. + if #imgs == 0 then + return + end local visible = self:visible() local stats = { new = 0, del = 0, update = 0 } for _, i in ipairs(imgs) do