From c8c9d1bebe874bc9401f39c55e59224f443b586a Mon Sep 17 00:00:00 2001 From: Matheus Afonso Martins Moreira Date: Sun, 7 Apr 2024 11:45:14 -0300 Subject: [PATCH] terminal: expand scrollback when scrolling If configured to do so, expand the scrollback capacity in order to hold the new rows without losing past output. --- terminal.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/terminal.c b/terminal.c index 8bd154af..4576a8f3 100644 --- a/terminal.c +++ b/terminal.c @@ -2815,6 +2815,8 @@ term_scroll_partial(struct terminal *term, struct scroll_region region, int rows /* Verify scroll amount has been clamped */ xassert(rows <= region.end - region.start); + bool expanded = term_expand_scrollback_capacity_if_needed(term, rows); + /* Cancel selections that cannot be scrolled */ if (unlikely(term->selection.coords.end.row >= 0)) { /* @@ -2838,7 +2840,13 @@ term_scroll_partial(struct terminal *term, struct scroll_region region, int rows bool view_follows = term->grid->view == term->grid->offset; term->grid->offset += rows; - term->grid->offset &= term->grid->num_rows - 1; + if (!expanded) { + /* Additional capacity was not allocated. + * Clamp down the offset and wrap it around + * so that old output lines are reused. + */ + term->grid->offset &= term->grid->num_rows - 1; + } if (likely(view_follows)) { term_damage_scroll(term, DAMAGE_SCROLL, region, rows);