@@ -59,11 +59,12 @@ impl Range {
59 #[must_use]
59 #[must_use]
60 pub fn overlaps(&self, other: &Self) -> bool {
60 pub fn overlaps(&self, other: &Self) -> bool {
61 // cursor overlap is checked differently
61 // cursor overlap is checked differently
62− // if self.is_empty() {
62+ if self.is_empty() {
63− // self.from() <= other.to()
64+ pos >= other.from() && other.to() >= pos
64− // } else {
65+ } else {
65− self.to() >= other.from() && other.to() >= self.from()
66+ self.to() > other.from() && other.to() > self.from()
69 pub fn contains(&self, pos: usize) -> bool {
70 pub fn contains(&self, pos: usize) -> bool {
@@ -159,13 +160,12 @@ impl Selection {
162− pub fn add(mut self, range: Range) -> Self {
163+ pub fn push(mut self, range: Range) -> Self {
163 let index = self.ranges.len();
164 let index = self.ranges.len();
164 self.ranges.push(range);
165 self.ranges.push(range);
166 Self::normalize(self.ranges, index)
167 Self::normalize(self.ranges, index)
168− // add_range // push
169 // replace_range
169 // replace_range
171 /// Map selections over a set of changes. Useful for adjusting the selection position after
171 /// Map selections over a set of changes. Useful for adjusting the selection position after
@@ -223,6 +223,9 @@ impl Selection {
223 // if previous value exists
223 // if previous value exists
224 if let Some(prev) = result.last_mut() {
224 if let Some(prev) = result.last_mut() {
225 // and we overlap it
225 // and we overlap it
227+ // TODO: we used to simply check range.from() <(=) prev.to()
228+ // avoiding two comparisons
226 if range.overlaps(prev) {
229 if range.overlaps(prev) {
227 let from = prev.from();
230 let from = prev.from();
228 let to = std::cmp::max(range.to(), prev.to());
231 let to = std::cmp::max(range.to(), prev.to());