mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-13 04:27:47 -05:00
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:
parent
b12ce3d7d7
commit
0e9eea85af
1 changed files with 17 additions and 2 deletions
19
grid.c
19
grid.c
|
|
@ -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]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue