1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-24 07:46:59 +03:00

Properly check the range intersection for invalidating selection

This commit is contained in:
Wez Furlong 2018-02-28 22:07:48 -08:00
parent f3149a5bf6
commit f986e0c6d8
2 changed files with 11 additions and 2 deletions

View File

@ -79,6 +79,15 @@ pub fn in_range<T: PartialOrd>(value: T, range: &Range<T>) -> bool {
value >= range.start && value < range.end
}
/// Returns true if r1 intersects r2
pub fn intersects_range<T: Ord + Copy>(r1: Range<T>, r2: Range<T>) -> bool {
use std::cmp::{max, min};
let start = max(r1.start, r2.start);
let end = min(r1.end, r2.end);
end > start
}
/// Position allows referring to an absolute visible row number
/// or a position relative to some existing row number (typically
/// where the cursor is located). Both of the cases are represented

View File

@ -213,7 +213,7 @@ impl TerminalState {
match sel {
Some(sel) => {
let sel_cols = sel.cols_for_row(row);
if cols.start >= sel_cols.start && cols.end <= sel_cols.end {
if intersects_range(cols, sel_cols) {
// Intersects, so clear the selection
self.clear_selection();
true
@ -239,7 +239,7 @@ impl TerminalState {
match sel {
Some(sel) => {
let sel_rows = sel.rows();
if rows.start >= sel_rows.start && rows.end <= sel_rows.end {
if intersects_range(rows, sel_rows) {
// Intersects, so clear the selection
self.clear_selection();
true