Compare anchors via their fragment and their offset within it

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Max Brunsfeld
2021-06-01 11:52:42 -07:00
co-authored by Nathan Sobo Antonio Scandurra
parent df13cf0a90
commit e3c07942d5
2 changed files with 25 additions and 27 deletions
+7 -22
View File
@@ -1,4 +1,4 @@
use super::{Buffer, ToOffset};
use super::Buffer;
use crate::{sum_tree, time};
use anyhow::Result;
use std::{cmp::Ordering, ops::Range};
@@ -61,30 +61,15 @@ impl Anchor {
(Anchor::End, _) | (_, Anchor::Start) => Ordering::Greater,
(
Anchor::Middle {
offset: self_offset,
bias: self_bias,
..
bias: self_bias, ..
},
Anchor::Middle {
offset: other_offset,
bias: other_bias,
..
bias: other_bias, ..
},
) => {
dbg!(
self,
other,
self_offset,
other_offset,
buffer.fragment_ix_for_anchor(self),
buffer.fragment_ix_for_anchor(other)
);
buffer
.fragment_ix_for_anchor(self)
.cmp(&buffer.fragment_ix_for_anchor(other))
.then_with(|| self_offset.cmp(&other_offset))
.then_with(|| self_bias.cmp(other_bias))
}
) => buffer
.fragment_ix_for_anchor(self)
.cmp(&buffer.fragment_ix_for_anchor(other))
.then_with(|| self_bias.cmp(&other_bias)),
})
}