aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2026-09-18 08:46:33 +0000
committerDaniel Eklöf <daniel@ekloef.se>2026-09-18 11:32:53 +0000
commitcb2771788998f6a6288e2de8273c55a8214551e0 (patch)
tree4aa78972c5df60f497b7504105d8aa59f5c1780d
parentshm: clang 23 complains max_pool_size is unused on x86 (which it is) (diff)
grid: reflow: fix two issues when truncating wide characters
When resizing to a very small grid, it may be impossible to fit a wide character (for example, a 6-cell character won't ever fit in a 5-cell grid). What we do is replace with wide character with a space. There were however two issues: 1. We never set the attributes of the space cell, only the wc member 2. We breaked out of the loop, causing any tracking points associated with any of the SPACER cells to never be matched. The last point is very real, since e.g. OSC-8 links cover the spacer cells. The first point is easy to fix; we first copy the entire cell from the old grid, then replace wc with 0. The second point is somewhat more complex. We remove the break, to ensure we run all the tracking point logic. Then, we only write the empty cell in the first iteration. Subsequent iterations do nothing (to the new grid). Then, to ensure tracking points associated with the spacer cells point to a valid cell, we keep the new_col_idx value at the first (now empty) cell. Only when we've processed the last SPACER cell do we increment new_col_idx once. This ensures consistency (the wide character was replaced with a single-cell character, thus new_col_idx should only be incremented by one).
-rw-r--r--grid.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/grid.c b/grid.c
index 459bf8f5..e0b18881 100644
--- a/grid.c
+++ b/grid.c
@@ -1087,21 +1087,35 @@ grid_resize_and_reflow(
new_row->shell_integration.cmd_end = new_col_idx;
if (unlikely(width > new_cols)) {
- /* Wide character no longer fits on a row, replace
- it with a single space */
- new_row->cells[new_col_idx++].wc = 0;
- c++;
-
- /* Walk past the SPACER cells */
- for (int i = 1; i < width; i++, c++, old++)
- ;
+ /*
+ * Wide character no longer fits on a row, replace
+ * it with a single space.
+ */
+ if (i == 0) {
+ /*
+ * Don't increment new_col_idx here, to ensure
+ * all the TP logic above maps to *this* cell
+ * for the subsequent SPACER cells we're
+ * skipping.
+ */
+ new_row->cells[new_col_idx] = *old;
+ new_row->cells[new_col_idx].wc = 0;
+ }
- /* Continue with next character in the *old* grid */
- break;
+ if (i == width - 1) {
+ /*
+ * Last SPACER - advance new_col_idx. This
+ * ensures we're consistent with the above -
+ * we've replaced a wide character with a
+ * single, empty cell, and advanced
+ * new_col_idx *once*.
+ */
+ new_col_idx++;
+ }
+ } else {
+ new_row->cells[new_col_idx++] = *old;
}
- new_row->cells[new_col_idx++] = *old;
-
/*
* TODO: simulate LCF instead?
*