From 9e6404be113f28f6755049075220460c08cecdeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 15 Feb 2020 18:56:16 +0100 Subject: [PATCH] render: reflow: bug: fix off-by-one The 'last-row' variable points to the last row the cursor is *on*, thus it's not a counter, and we need to add one when calculating the new grid offsets, or we get an off-by-one error. With this, there's no longer any need to scroll the reflowed text. --- render.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/render.c b/render.c index 14c534d0..3dd98533 100644 --- a/render.c +++ b/render.c @@ -1150,8 +1150,8 @@ maybe_resize(struct terminal *term, int width, int height, bool force) /* Reset offset such that the last copied row ends up at the * bottom of the screen */ - term->normal.offset = last_normal_row - new_rows; - term->alt.offset = last_alt_row - new_rows; + term->normal.offset = last_normal_row - new_rows + 1; + term->alt.offset = last_alt_row - new_rows + 1; /* Can't have negative offsets, so wrap 'em */ while (term->normal.offset < 0) @@ -1165,6 +1165,7 @@ maybe_resize(struct terminal *term, int width, int height, bool force) while (alt[term->alt.offset] == NULL) term->alt.offset = (term->alt.offset + 1) & (new_alt_grid_rows - 1); + /* TODO: try to keep old view */ term->normal.view = term->normal.offset; term->alt.view = term->alt.offset; @@ -1234,14 +1235,14 @@ maybe_resize(struct terminal *term, int width, int height, bool force) while (cursor_row < 0) cursor_row += term->grid->num_rows; + assert(cursor_row >= 0); + assert(cursor_row < term->rows); + term_cursor_to( term, - min(max(cursor_row, 0), term->rows - 1), + cursor_row, min(term->cursor.point.col, term->cols - 1)); - if (cursor_row >= term->rows) - term_linefeed(term); - term->render.last_cursor.cell = NULL; tll_free(term->normal.scroll_damage); tll_free(term->alt.scroll_damage);