From b7709cc013766c40a2f7cb286a043e84411d5dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 2 Jun 2021 19:32:05 +0200 Subject: [PATCH] =?UTF-8?q?grid:=20don=E2=80=99t=20cut=20multi-column=20ch?= =?UTF-8?q?ars=20in=20half=20when=20resizing=20the=20alt=20screen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we resize the alt screen, we don’t reflow the text, we simply truncate all the lines. When doing this, make sure we don’t truncate in the middle of a multi-column character. --- CHANGELOG.md | 2 ++ grid.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6305093..7e727ad6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -149,6 +149,8 @@ (https://codeberg.org/dnkl/foot/issues/565). * Off-by-one error in markup of auto-detected URLs when the URL ends in the right-most column. +* Multi-column characters being cut in half when resizing the + alternate screen. ### Security diff --git a/grid.c b/grid.c index c9080347..2787102f 100644 --- a/grid.c +++ b/grid.c @@ -194,11 +194,15 @@ grid_resize_without_reflow( new_row->dirty = old_row->dirty; new_row->linebreak = false; - /* Clear "new" columns */ if (new_cols > old_cols) { + /* Clear "new" columns */ memset(&new_row->cells[old_cols], 0, sizeof(struct cell) * (new_cols - old_cols)); new_row->dirty = true; + } else if (old_cols > new_cols) { + /* Make sure we don't cut a multi-column character in two */ + for (int i = new_cols; i > 0 && old_row->cells[i].wc > CELL_SPACER; i--) + new_row->cells[i - 1].wc = 0; } /* Map sixels on current "old" row to current "new row" */