From aaf10e76f2fe20924639aaab4398e4090bf66ad0 Mon Sep 17 00:00:00 2001 From: Adam Saponara Date: Sun, 21 Jul 2024 17:31:07 -0400 Subject: [PATCH] for cells skipped due to double-width chars, set them to invalid codepoints instead of null (0) which is a valid codepoint. --- termbox2.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/termbox2.h b/termbox2.h index 6ad6900..5fc791f 100644 --- a/termbox2.h +++ b/termbox2.h @@ -1666,6 +1666,7 @@ int tb_present(void) { send_attr(back->fg, back->bg); if (w > 1 && x >= global.front.width - (w - 1)) { + // Not enough room for wide char, send spaces for (i = x; i < global.front.width; i++) { send_char(i, y, ' '); } @@ -1678,12 +1679,20 @@ int tb_present(void) { #endif send_char(x, y, back->ch); } + + // When wcwidth>1, we need to advance the cursor by more + // than 1, thereby skipping some cells. Set these skipped + // cells to an invalid codepoint in the front buffer, so + // that if this cell is later replaced by a wcwidth==1 char, + // we'll get a cell_cmp diff for the skipped cells and + // properly re-render. for (i = 1; i < w; i++) { struct tb_cell *front_wide; + uint32_t invalid = -1; if_err_return(rv, cellbuf_get(&global.front, x + i, y, &front_wide)); if_err_return(rv, - cell_set(front_wide, 0, 1, back->fg, back->bg)); + cell_set(front_wide, &invalid, 1, -1, -1)); } } }