grid: reflow: handle viewport being too far down when enlarging the window

If the viewport is close to the bottom, but not *at* the bottom, and
we’re enlarging the window, the translated viewport will be too far
down.
This commit is contained in:
Daniel Eklöf 2020-09-24 18:48:41 +02:00
parent b12ce3d7d7
commit 0e9eea85af
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

19
grid.c
View file

@ -317,8 +317,6 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols,
while (new_grid[grid->offset] == NULL)
grid->offset = (grid->offset + 1) & (new_rows - 1);
grid->view = view_follows ? grid->offset : viewport.row;
/* Ensure all visible rows have been allocated */
for (int r = 0; r < new_screen_rows; r++) {
int idx = (grid->offset + r) & (new_rows - 1);
@ -326,6 +324,23 @@ grid_reflow(struct grid *grid, int new_rows, int new_cols,
new_grid[idx] = grid_row_alloc(new_cols, true);
}
grid->view = view_follows ? grid->offset : viewport.row;
/* If enlarging the window, the old viewport may be too far down,
* with unallocated rows. Make sure this cannot happen */
while (true) {
int idx = (grid->view + new_screen_rows - 1) & (new_rows - 1);
if (new_grid[idx] != NULL)
break;
grid->view--;
if (grid->view < 0)
grid->view += new_rows;
}
for (size_t r = 0; r < new_screen_rows; r++) {
int idx = (grid->view + r) & (new_rows - 1);
assert(new_grid[idx] != NULL);
}
/* Free old grid */
for (int r = 0; r < grid->num_rows; r++)
grid_row_free(old_grid[r]);