grid: reflow: handle composed characters longer than 2 cells

The logic that tries to ensure we don't break a line in the middle of
a multi-cell character was flawed when the number of cells were larger
than 2.

In particular, if the number of cells to copy were limited by the
number of cells left on the current (new) line, and were less than the
length of the multi-cell character, then we failed to insert the
correct number of spacers, and also ended up misplacing the multi-cell
character; instead of pushing it to the next line, it was inserted on
the current line, even though it doesn't fit.

Also change how trailing SPACER cells are rendered (cells that are
"fillers" at then end of a line, when a multi-column character was
pushed over to the next line): don't copy the previous cell's
attributes (which may be wrong anyway), use default attributes
instead.
This commit is contained in:
Daniel Eklöf 2025-01-25 14:06:30 +01:00
parent e248e73753
commit 1111f7e918
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 4 additions and 6 deletions

8
grid.c
View file

@ -1052,7 +1052,7 @@ grid_resize_and_reflow(
*/ */
while ( while (
unlikely( unlikely(
amount > 1 && amount > 0 &&
from + amount < old_cols && from + amount < old_cols &&
old_row->cells[from + amount].wc >= CELL_SPACER + 1)) old_row->cells[from + amount].wc >= CELL_SPACER + 1))
{ {
@ -1061,7 +1061,7 @@ grid_resize_and_reflow(
} }
xassert( xassert(
amount == 1 || amount <= 1 ||
old_row->cells[from + amount - 1].wc <= CELL_SPACER + 1); old_row->cells[from + amount - 1].wc <= CELL_SPACER + 1);
} }
@ -1084,11 +1084,9 @@ grid_resize_and_reflow(
if (unlikely(spacers > 0)) { if (unlikely(spacers > 0)) {
xassert(new_col_idx + spacers == new_cols); xassert(new_col_idx + spacers == new_cols);
const struct cell *cell = &old_row->cells[from - 1];
for (int i = 0; i < spacers; i++, new_col_idx++) { for (int i = 0; i < spacers; i++, new_col_idx++) {
new_row->cells[new_col_idx].wc = CELL_SPACER; new_row->cells[new_col_idx].wc = CELL_SPACER;
new_row->cells[new_col_idx].attrs = cell->attrs; new_row->cells[new_col_idx].attrs = (struct attributes){0};
} }
} }
} }

View file

@ -3826,7 +3826,7 @@ print_spacer(struct terminal *term, int col, int remaining)
struct cell *cell = &row->cells[col]; struct cell *cell = &row->cells[col];
cell->wc = CELL_SPACER + remaining; cell->wc = CELL_SPACER + remaining;
cell->attrs = term->vt.attrs; cell->attrs = (struct attributes){0};
} }
/* /*