render: make sure the current view is allocated and visible

This commit is contained in:
Daniel Eklöf 2019-08-04 18:34:14 +02:00
parent e2e1db8faf
commit c411dedc3b
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -693,15 +693,21 @@ render_resize(struct terminal *term, int width, int height)
const int new_normal_grid_rows = new_rows + scrollback_lines;
const int new_alt_grid_rows = new_rows;
term->normal.offset %= new_normal_grid_rows;
term->normal.view %= new_normal_grid_rows;
term->alt.offset %= new_alt_grid_rows;
term->alt.view %= new_alt_grid_rows;
/* Allocate new 'normal' grid */
struct row **normal = calloc(new_normal_grid_rows, sizeof(normal[0]));
for (int r = 0; r < new_rows; r++)
normal[r] = grid_row_alloc(new_cols);
normal[(term->normal.view + r) % new_normal_grid_rows] = grid_row_alloc(new_cols);
/* Allocate new 'alt' grid */
struct row **alt = calloc(new_alt_grid_rows, sizeof(alt[0]));
for (int r = 0; r < new_rows; r++)
alt[r] = grid_row_alloc(new_cols);
alt[(term->alt.view + r) % new_alt_grid_rows] = grid_row_alloc(new_cols);
/* Reflow content */
reflow(normal, new_cols, new_normal_grid_rows,
@ -749,12 +755,6 @@ render_resize(struct terminal *term, int width, int height)
if (term->scroll_region.end >= old_rows)
term->scroll_region.end = term->rows;
term->normal.offset %= term->normal.num_rows;
term->normal.view %= term->normal.num_rows;
term->alt.offset %= term->alt.num_rows;
term->alt.view %= term->alt.num_rows;
term_cursor_to(
term,
min(term->cursor.row, term->rows - 1),