From 6898e26a7a464d456c58cdc2dee8230120ae1150 Mon Sep 17 00:00:00 2001 From: Michael Grant Date: Tue, 24 Feb 2026 01:19:24 +0000 Subject: [PATCH] Fix bug with utf-8 extended characters not respecting visible range. --- screen-write.c | 10 +++++----- tty-draw.c | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/screen-write.c b/screen-write.c index ecbd9e11..813606da 100644 --- a/screen-write.c +++ b/screen-write.c @@ -2254,6 +2254,9 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc) if (selected) skip = 0; + /* xxx cache r in wp ? */ + r = screen_redraw_get_visible_ranges(wp, s->cx, s->cy, width, NULL); + /* * Move the cursor. If not wrapping, stick at the last character and * replace it. @@ -2279,10 +2282,7 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc) memcpy(&tmp_gc, gc, sizeof tmp_gc); ttyctx.cell = &tmp_gc; ttyctx.num = redraw ? 2 : 0; - /* xxx to be cached in wp */ - r = screen_redraw_get_visible_ranges(wp, s->cx, s->cy, width, - NULL); - for (i=0; i < r->used; i++) vis += r->ranges[i].nx; + for (i=0, vis=0; i < r->used; i++) vis += r->ranges[i].nx; if (vis < width) { /* Wide character or tab partly obscured. Write * spaces one by one in unobscured region(s). @@ -2411,7 +2411,7 @@ screen_write_combine(struct screen_write_ctx *ctx, const struct grid_cell *gc) * could be an empty range in the visible ranges so we add them all up. */ r = screen_redraw_get_visible_ranges(wp, cx - n, cy, n, NULL); - for (i=0; i < r->used; i++) vis += r->ranges[i].nx; + for (i=0, vis=0; i < r->used; i++) vis += r->ranges[i].nx; if (vis < n) { /* * Part of this character is obscured. Return 1 diff --git a/tty-draw.c b/tty-draw.c index 080ea42b..a27b2d0d 100644 --- a/tty-draw.c +++ b/tty-draw.c @@ -223,6 +223,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx, */ empty = 0; next_state = TTY_DRAW_LINE_DONE; + gcp = &grid_default_cell; } else { /* Get the current cell. */ grid_view_get_cell(gd, px + i, py, &gc);