|
|
@ -59,11 +59,12 @@ impl Range {
|
|
|
|
#[must_use]
|
|
|
|
#[must_use]
|
|
|
|
pub fn overlaps(&self, other: &Self) -> bool {
|
|
|
|
pub fn overlaps(&self, other: &Self) -> bool {
|
|
|
|
// cursor overlap is checked differently
|
|
|
|
// cursor overlap is checked differently
|
|
|
|
// if self.is_empty() {
|
|
|
|
if self.is_empty() {
|
|
|
|
// self.from() <= other.to()
|
|
|
|
let pos = self.head;
|
|
|
|
// } else {
|
|
|
|
pos >= other.from() && other.to() >= pos
|
|
|
|
self.to() >= other.from() && other.to() >= self.from()
|
|
|
|
} else {
|
|
|
|
// }
|
|
|
|
self.to() > other.from() && other.to() > self.from()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn contains(&self, pos: usize) -> bool {
|
|
|
|
pub fn contains(&self, pos: usize) -> bool {
|
|
|
@ -159,13 +160,12 @@ impl Selection {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn add(mut self, range: Range) -> Self {
|
|
|
|
pub fn push(mut self, range: Range) -> Self {
|
|
|
|
let index = self.ranges.len();
|
|
|
|
let index = self.ranges.len();
|
|
|
|
self.ranges.push(range);
|
|
|
|
self.ranges.push(range);
|
|
|
|
|
|
|
|
|
|
|
|
Self::normalize(self.ranges, index)
|
|
|
|
Self::normalize(self.ranges, index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// add_range // push
|
|
|
|
|
|
|
|
// replace_range
|
|
|
|
// replace_range
|
|
|
|
|
|
|
|
|
|
|
|
/// Map selections over a set of changes. Useful for adjusting the selection position after
|
|
|
|
/// Map selections over a set of changes. Useful for adjusting the selection position after
|
|
|
@ -223,6 +223,9 @@ impl Selection {
|
|
|
|
// if previous value exists
|
|
|
|
// if previous value exists
|
|
|
|
if let Some(prev) = result.last_mut() {
|
|
|
|
if let Some(prev) = result.last_mut() {
|
|
|
|
// and we overlap it
|
|
|
|
// and we overlap it
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: we used to simply check range.from() <(=) prev.to()
|
|
|
|
|
|
|
|
// avoiding two comparisons
|
|
|
|
if range.overlaps(prev) {
|
|
|
|
if range.overlaps(prev) {
|
|
|
|
let from = prev.from();
|
|
|
|
let from = prev.from();
|
|
|
|
let to = std::cmp::max(range.to(), prev.to());
|
|
|
|
let to = std::cmp::max(range.to(), prev.to());
|
|
|
|