From ed63826b151e40c718c8833b97c090d70a5b77f6 Mon Sep 17 00:00:00 2001 From: Michael Grant Date: Sat, 8 Aug 2026 22:16:24 +0100 Subject: [PATCH] Cleanup. --- image-kitty.c | 2 -- input.c | 24 ++++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/image-kitty.c b/image-kitty.c index 5798349a9..b27853923 100644 --- a/image-kitty.c +++ b/image-kitty.c @@ -861,7 +861,6 @@ kitty_place_image(struct image *source, struct kitty_state *ks, u_int xpixel, * static images are accepted. The returned image retains immutable RGBA * pixels for the lifetime of its placement. */ -/* Parse Kitty graphics data and return a placed image when appropriate. */ struct image * kitty_parse_image(void **state, const u_char *buf, size_t len, u_int xpixel, u_int ypixel, u_int *image_id, u_int *replace_id, u_int *quiet, @@ -1120,7 +1119,6 @@ kitty_placeholder_index(uint32_t value, u_int *index) return (0); } -/* Replace a Kitty Unicode placeholder with a shared image marker cell. */ /* Convert a Kitty Unicode placeholder cell into an image marker. */ int kitty_placeholder_to_cell(void *state, struct grid_cell *gc, diff --git a/input.c b/input.c index dc782e2d1..2f633df1c 100644 --- a/input.c +++ b/input.c @@ -2923,6 +2923,11 @@ input_top_bit_set(struct input_ctx *ictx) { struct screen_write_ctx *sctx = &ictx->ctx; struct utf8_data *ud = &ictx->utf8data; +#ifdef ENABLE_IMAGES + struct grid_cell gc, left; + const struct grid_cell *gcl; + u_int x; +#endif ictx->flags &= ~INPUT_LAST; @@ -2952,15 +2957,18 @@ input_top_bit_set(struct input_ctx *ictx) #ifdef ENABLE_IMAGES if (sctx->s->cx != 0) { - struct grid_cell gc, left; - u_int x = sctx->s->cx - 1; - + x = sctx->s->cx - 1; /* cx-1 is the cell just written. */ grid_view_get_cell(sctx->s->grid, x, sctx->s->cy, &gc); - if (x != 0) - grid_view_get_cell(sctx->s->grid, x - 1, sctx->s->cy, - &left); - if (kitty_placeholder_to_cell(ictx->kitty_state, &gc, - x == 0 ? NULL : &left)) { + /* The preceding cell provides context for implicit coordinates. */ + if (x == 0) { + gcl = NULL; + } else { + grid_view_get_cell(sctx->s->grid, x - 1, sctx->s->cy, &left); + gcl = &left; + } + + /* Convert a recognized Kitty placeholder in gc to an image marker. */ + if (kitty_placeholder_to_cell(ictx->kitty_state, &gc, gcl)) { grid_view_set_cell(sctx->s->grid, x, sctx->s->cy, &gc); image_redraw_area(sctx, x, sctx->s->cy, 1, 1); }