Skip to content

fix(image.inline): keep placements when find_visible returns no images#2898

Open
carlos-algms wants to merge 1 commit into
folke:mainfrom
carlos-algms:fix/image-inline-flicker
Open

fix(image.inline): keep placements when find_visible returns no images#2898
carlos-algms wants to merge 1 commit into
folke:mainfrom
carlos-algms:fix/image-inline-flicker

Conversation

@carlos-algms

@carlos-algms carlos-algms commented Jun 28, 2026

Copy link
Copy Markdown

Description

Inline images flicker on rapidly-appending buffers (e.g. streaming chat output into a markdown buffer with an inline image).

Snacks.image.doc.find_visible is treesitter-backed and intermittently returns zero images while the parser is mid-reparse during streaming, even though the image is still in the buffer.

Treat an empty result as inconclusive: keep existing placements, reconcile only when find_visible reports images.

Tradeoff: N images → 0 defers closing the last placement until a later non-empty find_visible.

One-line guard; no behavior change for non-streaming buffers.

`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`.
@github-actions github-actions Bot added image size/s Small PR (<10 lines changed) labels Jun 28, 2026
@carlos-algms
carlos-algms marked this pull request as ready for review June 28, 2026 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

image size/s Small PR (<10 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant