From 5f0ceb72f176caf7673ea1d4bc5195f26f4b4df7 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 16 Jul 2021 16:45:36 +0200 Subject: csi: erase scrollback: cancel selection if it touches the scrollback This breaks out the scrollback erasing logic for \E[3J from csi.c, and moves it to the new function term_erase_scrollback(), and changes the logic to calculate the start and end row (absolute) numbers of the scrollback, and only iterate those, instead of iterating *all* rows, filtering out those that are on-screen. It also adds an intersection range check of the selection range, and cancels the selection if it touches any of the deleted scrollback rows. This fixes a crash when trying to render the next frame, since the selection now references rows that have been freed. Closes #633 --- csi.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'csi.c') diff --git a/csi.c b/csi.c index 80ee75cd..dc5a018a 100644 --- a/csi.c +++ b/csi.c @@ -917,26 +917,7 @@ csi_dispatch(struct terminal *term, uint8_t final) case 3: { /* Erase scrollback */ - int end = (term->grid->offset + term->rows - 1) % term->grid->num_rows; - for (size_t i = 0; i < term->grid->num_rows; i++) { - if (end >= term->grid->offset) { - /* Not wrapped */ - if (i >= term->grid->offset && i <= end) - continue; - } else { - /* Wrapped */ - if (i >= term->grid->offset || i <= end) - continue; - } - - if (term->render.last_cursor.row == term->grid->rows[i]) - term->render.last_cursor.row = NULL; - - grid_row_free(term->grid->rows[i]); - term->grid->rows[i] = NULL; - } - term->grid->view = term->grid->offset; - term_damage_view(term); + term_erase_scrollback(term); break; } -- cgit v1.3