From a6a13311b4e63c735cac9d6ac9ecedad752d31d7 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 24 Jul 2019 18:56:07 +0100 Subject: [PATCH] Revert "Bounds-check terminal selection when clearing scrollback." This reverts commit 80f5a009f647aacd492c6e1e7a5f450156cabe13. After a bit more thought, I've decided it's the wrong way to solve the problem. We shouldn't really be _changing_ the current selection bounds in response to an event that touches the range they cover. With this fix in place, if you clear the scrollback while a selection partly overlaps it, and then extend the modified selection, you'll get a selection one of whose endpoints is something you never specified as a selection endpoint at all, and possibly paste the wrong text. A better fix is to do the same thing we do about any other event that touches the range covered by the selection: get rid of the selection completely. For ease of cherry-picking (in case anyone needs to apply the good fix in some downstream branch, or whatever), I'll make that change separately in the next commit. --- terminal.c | 23 ----------------------- terminal.h | 5 ----- 2 files changed, 28 deletions(-) diff --git a/terminal.c b/terminal.c index a0596b8d..c1a12c04 100644 --- a/terminal.c +++ b/terminal.c @@ -1600,24 +1600,6 @@ void term_reconfig(Terminal *term, Conf *conf) term_copy_stuff_from_conf(term); } -/* - * Ensure the position variables describing the ends of the terminal - * selection are in bounds with respect to the actual extent of the - * screen and scrollback. - */ -static void term_selection_bounds_check(Terminal *term) -{ - pos lo, hi; - lo.y = -count234(term->scrollback); - lo.x = 0; - hi.y = count234(term->screen); - hi.x = term->cols - 1; - - term->selstart = bound_pos(term->selstart, lo, hi); - term->selend = bound_pos(term->selend, lo, hi); - term->selanchor = bound_pos(term->selanchor, lo, hi); -} - /* * Clear the scrollback. */ @@ -1639,11 +1621,6 @@ void term_clrsb(Terminal *term) sfree(line); /* this is compressed data, not a termline */ } - /* - * Make sure we didn't invalidate selstart and selend in the process. - */ - term_selection_bounds_check(term); - /* * When clearing the scrollback, we also truncate any termlines on * the current screen which have remembered data from a previous diff --git a/terminal.h b/terminal.h index 8da3b9b4..1ed0b17d 100644 --- a/terminal.h +++ b/terminal.h @@ -475,9 +475,4 @@ static inline bool decpos_fn(pos *p, int cols) #define incpos(p) incpos_fn(&(p), GET_TERM_COLS) #define decpos(p) decpos_fn(&(p), GET_TERM_COLS) -static inline pos bound_pos(pos p, pos lo, pos hi) -{ - return poslt(p, lo) ? lo : poslt(p, hi) ? p : hi; -} - #endif