@@ -59,11 +59,12 @@ impl Range {
5959 #[must_use]
6060 pub fn overlaps(&self, other: &Self) -> bool {
6161 // cursor overlap is checked differently
62− // if self.is_empty() {
63− // self.from() <= other.to()
64− // } else {
65− self.to() >= other.from() && other.to() >= self.from()
66− // }
62+ if self.is_empty() {
63+ let pos = self.head;
64+ pos >= other.from() && other.to() >= pos
65+ } else {
66+ self.to() > other.from() && other.to() > self.from()
67+ }
6768 }
6869
6970 pub fn contains(&self, pos: usize) -> bool {
@@ -159,13 +160,12 @@ impl Selection {
159160 }
160161 }
161162
162− pub fn add(mut self, range: Range) -> Self {
163+ pub fn push(mut self, range: Range) -> Self {
163164 let index = self.ranges.len();
164165 self.ranges.push(range);
165166
166167 Self::normalize(self.ranges, index)
167168 }
168− // add_range // push
169169 // replace_range
170170
171171 /// Map selections over a set of changes. Useful for adjusting the selection position after
@@ -223,6 +223,9 @@ impl Selection {
223223 // if previous value exists
224224 if let Some(prev) = result.last_mut() {
225225 // and we overlap it
226+
227+ // TODO: we used to simply check range.from() <(=) prev.to()
228+ // avoiding two comparisons
226229 if range.overlaps(prev) {
227230 let from = prev.from();
228231 let to = std::cmp::max(range.to(), prev.to());