diff --git a/CHANGELOG.md b/CHANGELOG.md index b82cfa00..1dddd2d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -109,6 +109,7 @@ * Poor performance when making very large selections ([#1114][1114]). * Bogus error message when using systemd socket activation for server mode ([#1107][1107]) +* Empty line at the bottom after a window resize ([#1108][1108]). [1055]: https://codeberg.org/dnkl/foot/issues/1055 [1092]: https://codeberg.org/dnkl/foot/issues/1092 @@ -117,6 +118,7 @@ [1120]: https://codeberg.org/dnkl/foot/issues/1120 [1114]: https://codeberg.org/dnkl/foot/issues/1114 [1107]: https://codeberg.org/dnkl/foot/issues/1107 +[1108]: https://codeberg.org/dnkl/foot/issues/1108 ### Security diff --git a/grid.c b/grid.c index 2790d16b..f40803e1 100644 --- a/grid.c +++ b/grid.c @@ -984,6 +984,26 @@ grid_resize_and_reflow( /* Set offset such that the last reflowed row is at the bottom */ grid->offset = new_row_idx - new_screen_rows + 1; + + if (new_col_idx == 0) { + int next_to_last_new_row_idx = new_row_idx - 1; + next_to_last_new_row_idx += new_rows; + next_to_last_new_row_idx &= new_rows - 1; + + const struct row *next_to_last_row = new_grid[next_to_last_new_row_idx]; + if (next_to_last_row != NULL && next_to_last_row->linebreak) { + /* + * The next to last row is actually the *last* row. But we + * ended the reflow with a line-break, causing an empty + * row to be inserted at the bottom. Undo this. + */ + /* TODO: can we detect this in the reflow loop above instead? */ + grid->offset--; + grid_row_free(new_grid[new_row_idx]); + new_grid[new_row_idx] = NULL; + } + } + while (grid->offset < 0) grid->offset += new_rows; while (new_grid[grid->offset] == NULL)