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.
This commit is contained in:
Daniel Eklöf 2022-10-14 18:03:00 +02:00
parent 3d9a429499
commit 89744f8123
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -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);
}