diff --git a/src/terminal/buffer.c b/src/terminal/buffer.c index 995ce3295e..bd6ad4f768 100644 --- a/src/terminal/buffer.c +++ b/src/terminal/buffer.c @@ -427,16 +427,20 @@ void guac_terminal_buffer_copy_rows(guac_terminal_buffer* buffer, } -void guac_terminal_buffer_scroll_up(guac_terminal_buffer* buffer, int amount) { +void guac_terminal_buffer_scroll_up(guac_terminal_buffer* buffer, int amount, + bool increase_length) { if (amount <= 0) return; buffer->top = (buffer->top + amount) % buffer->available; - buffer->length += amount; - if (buffer->length > buffer->available) - buffer->length = buffer->available; + /* Increase buffer length only if new row is added */ + if (increase_length) { + buffer->length += amount; + if (buffer->length > buffer->available) + buffer->length = buffer->available; + } } diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 27a2bf84a4..0600df51ea 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -834,8 +834,8 @@ void guac_terminal_scroll_up(guac_terminal* term, /* Scroll up visibly */ guac_terminal_display_copy_rows(term->display, start_row + amount, end_row, -amount); - /* Advance by scroll amount */ - guac_terminal_buffer_scroll_up(term->current_buffer, amount); + /* Advance and increase buffer length by scroll amount */ + guac_terminal_buffer_scroll_up(term->current_buffer, amount, true); /* Reset scrollbar bounds */ guac_terminal_scrollbar_set_bounds(term->scrollbar, @@ -1225,7 +1225,7 @@ static void __guac_terminal_resize(guac_terminal* term, int width, int height) { shift_amount, term->display->height - 1, -shift_amount); /* Update buffer top and cursor row based on shift */ - guac_terminal_buffer_scroll_up(term->current_buffer, shift_amount); + guac_terminal_buffer_scroll_up(term->current_buffer, shift_amount, false); term->cursor_row -= shift_amount; if (term->visible_cursor_row != -1) term->visible_cursor_row -= shift_amount; @@ -1296,6 +1296,10 @@ static void __guac_terminal_resize(guac_terminal* term, int width, int height) { /* Draw characters at top from scroll */ __guac_terminal_redraw_rect(term, 0, 0, shift_amount - 1, width-1); + /* Draw characters from scroll at bottom */ + __guac_terminal_redraw_rect(term, term->display->height - shift_amount, + 0, term->display->height - 1, width-1); + } } diff --git a/src/terminal/terminal/buffer.h b/src/terminal/terminal/buffer.h index 9f175ba140..f27af74f8c 100644 --- a/src/terminal/terminal/buffer.h +++ b/src/terminal/terminal/buffer.h @@ -91,8 +91,13 @@ void guac_terminal_buffer_copy_rows(guac_terminal_buffer* buffer, * @param amount * The number of rows to scroll upwards. Zero and negative values have no * effect. + * + * @param increase_length + * Whether the length of the buffer should be increased to account for + * newly added rows. If false, the length of the buffer remains unchanged. */ -void guac_terminal_buffer_scroll_up(guac_terminal_buffer* buffer, int amount); +void guac_terminal_buffer_scroll_up(guac_terminal_buffer* buffer, int amount, + bool increase_length); /** * Scrolls the contents of the given buffer down by the given number of rows.