From 89744f8123aadd58b74ea7b5038c3302c1ed75ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 14 Oct 2022 18:03:00 +0200 Subject: [PATCH] selection: scroll down: handle non-full scrollback correctly When determining whether or not to cancel a selection (due to it, or part of it, being "scrolled out"), we assumed the scrollback was full. This patch changes the implementation to compare the scrollback relative selection coordinates with the scrollback relative end-of-the-scrollback coordinates. --- selection.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/selection.c b/selection.c index c94686e1..92f1f85f 100644 --- a/selection.c +++ b/selection.c @@ -133,13 +133,18 @@ selection_scroll_down(struct terminal *term, int rows) { xassert(term->selection.coords.end.row >= 0); + const struct grid *grid = term->grid; + const struct range *sel = &term->selection.coords; + + const int screen_end = + grid_row_abs_to_sb(grid, term->rows, grid->offset + term->rows - 1); const int rel_row_start = - grid_row_abs_to_sb(term->grid, term->rows, term->selection.coords.start.row); + grid_row_abs_to_sb(term->grid, term->rows, sel->start.row); const int rel_row_end = - grid_row_abs_to_sb(term->grid, term->rows, term->selection.coords.end.row); + grid_row_abs_to_sb(term->grid, term->rows, sel->end.row); const int actual_end = max(rel_row_start, rel_row_end); - if (actual_end + rows <= term->grid->num_rows) { + if (actual_end > screen_end - rows) { /* Part of the selection will be scrolled out, cancel it */ selection_cancel(term); }