Merge branch 'fragment-locators' into project-diagnostics

This commit is contained in:
Antonio Scandurra 2021-12-10 14:01:17 +01:00
commit c8d5e19492
7 changed files with 34 additions and 28 deletions

View file

@ -1768,12 +1768,11 @@ impl BufferSnapshot {
}
}
fn full_offset_for_anchor(&self, anchor: &Anchor) -> FullOffset {
fn fragment_id_for_anchor(&self, anchor: &Anchor) -> &Locator {
if *anchor == Anchor::min() {
Default::default()
&locator::MIN
} else if *anchor == Anchor::max() {
let text = self.fragments.summary().text;
FullOffset(text.visible + text.deleted)
&locator::MAX
} else {
let anchor_key = InsertionFragmentKey {
timestamp: anchor.timestamp,
@ -1795,10 +1794,7 @@ impl BufferSnapshot {
}
let insertion = insertion_cursor.item().expect("invalid insertion");
debug_assert_eq!(insertion.timestamp, anchor.timestamp, "invalid insertion");
let mut fragment_cursor = self.fragments.cursor::<(Option<&Locator>, FullOffset)>();
fragment_cursor.seek(&Some(&insertion.fragment_id), Bias::Left, &None);
fragment_cursor.start().1 + (anchor.offset - insertion.split_offset)
&insertion.fragment_id
}
}