From e860c7d6a889aba383574f2abd0da55eff373d55 Mon Sep 17 00:00:00 2001 From: Zsolt Simon Date: Fri, 31 Jul 2026 14:43:51 +1000 Subject: [PATCH] fix(document): cap popup size at the image's natural size 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 --- lua/image/utils/document.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lua/image/utils/document.lua b/lua/image/utils/document.lua index 4d90ef4..5c70ae3 100644 --- a/lua/image/utils/document.lua +++ b/lua/image/utils/document.lua @@ -141,13 +141,21 @@ local create_document_integration = function(config) local term_size = utils.term.get_size() if not term_size then return end + + -- Cap at the image's natural width, not an unconditional screen_cols/2 -- + -- otherwise a 78x20 badge also gets a half-screen window. + 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)) local width, height = utils.math.adjust_to_aspect_ratio( term_size, image.image_width, image.image_height, - math.floor(term_size.screen_cols / 2), + math.max(1, requested_cols), 0 ) + + -- Aspect-ratio fitting can still overshoot vertically on a tall image. + height = math.min(height, math.max(1, term_size.screen_rows - 4)) local win_config = { relative = "cursor", row = 1,