From c06f141189c51450be3bfd896b9df7a9d423e79d Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 5 Aug 2019 20:16:17 +0200 Subject: term: cancel selection when scrolling wraps If we scroll enough, we'll eventually end up wrapping around the entire scrollback buffer. At this point, a selection is no longer valid, so cancel it. Note: this was very obvious when scrolling in the alt screen, since its scrollback buffer is what you see on the screen (i.e. it has no scrollback). --- selection.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'selection.c') diff --git a/selection.c b/selection.c index fe4f4297..f69338a4 100644 --- a/selection.c +++ b/selection.c @@ -24,6 +24,20 @@ selection_enabled(const struct terminal *term) term->mouse_tracking != MOUSE_MOTION); } +bool +selection_on_row_in_view(const struct terminal *term, int row_no) +{ + if (term->selection.start.row == -1 || term->selection.end.row == -1) + return false; + + const struct coord *start = &term->selection.start; + const struct coord *end = &term->selection.end; + assert(start->row <= end->row); + + row_no += term->grid->view; + return row_no >= start->row && row_no <= end->row; +} + static char * extract_selection(const struct terminal *term) { -- cgit v1.3