Use offset to restore navigation position if anchor can't be resolved

This commit is contained in:
Antonio Scandurra 2022-01-18 09:59:28 +01:00
parent d480738cc5
commit d5acbe1e32
4 changed files with 39 additions and 12 deletions

View file

@ -1545,6 +1545,18 @@ impl MultiBufferSnapshot {
panic!("excerpt not found");
}
pub fn can_resolve(&self, anchor: &Anchor) -> bool {
if anchor.excerpt_id == ExcerptId::min() || anchor.excerpt_id == ExcerptId::max() {
true
} else if let Some((buffer_id, buffer_snapshot)) =
self.buffer_snapshot_for_excerpt(&anchor.excerpt_id)
{
anchor.buffer_id == buffer_id && buffer_snapshot.can_resolve(&anchor.text_anchor)
} else {
false
}
}
pub fn range_contains_excerpt_boundary<T: ToOffset>(&self, range: Range<T>) -> bool {
let start = range.start.to_offset(self);
let end = range.end.to_offset(self);