Skip to content

fix(document): cap popup size at the image's natural size - #375

Open
szsolt wants to merge 1 commit into
3rd:masterfrom
szsolt:popup-size-cap
Open

fix(document): cap popup size at the image's natural size#375
szsolt wants to merge 1 commit into
3rd:masterfrom
szsolt:popup-size-cap

Conversation

@szsolt

@szsolt szsolt commented Jul 31, 2026

Copy link
Copy Markdown

Problem

With only_render_image_at_cursor_mode = "popup", the popup window is always sized at
half the screen width, regardless of how large the image actually is. A small image — a
78x20 shields.io badge, say — gets a half-screen float with the image in one corner and a
large empty region beside it.

The aspect-ratio fit can also overshoot vertically on a tall, narrow image, pushing the
float past the bottom of the screen.

Change

Cap the requested width at the image's natural size in cells, so the popup never asks for
more room than the image can fill:

local natural_cols = math.ceil(image.image_width / term_size.cell_width)
local requested_cols = math.min(natural_cols, math.floor(term_size.screen_cols / 2))

Half the screen remains the upper bound, so large images behave exactly as before — only
images narrower than that are affected.

Then clamp the fitted height to the screen:

height = math.min(height, math.max(1, term_size.screen_rows - 4))

Notes

Platform-independent; not specific to any backend or terminal. Verified with badge-sized
and full-width images in a markdown buffer.

render_popup_image asked for screen_cols/2 regardless of the image, so a
78x20 badge got the same half-screen window as a 1400px chart, and with tall
cells the derived height filled most of the screen.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant