Properly check the range intersection for invalidating selection

This commit is contained in:
Wez Furlong committed 2018-02-28 22:07:48 -08:00
1 parent f3149a5bf6
commit f986e0c6d8
2 files changed
+11 -2

No files matched your search

+9
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
+2 -2
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