Assume the anchor is valid if we can find an excerpt that contains it
This commit is contained in:
parent
5407f25c94
commit
a74b602f18
2 changed files with 35 additions and 48 deletions
|
@ -41,22 +41,7 @@ impl Anchor {
|
|||
if self.excerpt_id == ExcerptId::min() || self.excerpt_id == ExcerptId::max() {
|
||||
Ok(Ordering::Equal)
|
||||
} else if let Some(excerpt) = snapshot.excerpt(&self.excerpt_id) {
|
||||
// Even though the anchor refers to a valid excerpt the underlying buffer might have
|
||||
// changed. In that case, treat the anchor as if it were at the start of that
|
||||
// excerpt.
|
||||
if self.buffer_id == Some(excerpt.buffer_id)
|
||||
&& other.buffer_id == Some(excerpt.buffer_id)
|
||||
{
|
||||
let self_anchor = excerpt.clip_anchor(self.text_anchor.clone());
|
||||
let other_anchor = excerpt.clip_anchor(other.text_anchor.clone());
|
||||
self_anchor.cmp(&other_anchor, &excerpt.buffer)
|
||||
} else if self.buffer_id == Some(excerpt.buffer_id) {
|
||||
Ok(Ordering::Greater)
|
||||
} else if other.buffer_id == Some(excerpt.buffer_id) {
|
||||
Ok(Ordering::Less)
|
||||
} else {
|
||||
Ok(Ordering::Equal)
|
||||
}
|
||||
self.text_anchor.cmp(&other.text_anchor, &excerpt.buffer)
|
||||
} else {
|
||||
Ok(Ordering::Equal)
|
||||
}
|
||||
|
@ -68,13 +53,11 @@ impl Anchor {
|
|||
pub fn bias_left(&self, snapshot: &MultiBufferSnapshot) -> Anchor {
|
||||
if self.text_anchor.bias != Bias::Left {
|
||||
if let Some(excerpt) = snapshot.excerpt(&self.excerpt_id) {
|
||||
if self.buffer_id == Some(excerpt.buffer_id) {
|
||||
return Self {
|
||||
buffer_id: self.buffer_id,
|
||||
excerpt_id: self.excerpt_id.clone(),
|
||||
text_anchor: self.text_anchor.bias_left(&excerpt.buffer),
|
||||
};
|
||||
}
|
||||
return Self {
|
||||
buffer_id: self.buffer_id,
|
||||
excerpt_id: self.excerpt_id.clone(),
|
||||
text_anchor: self.text_anchor.bias_left(&excerpt.buffer),
|
||||
};
|
||||
}
|
||||
}
|
||||
self.clone()
|
||||
|
@ -83,13 +66,11 @@ impl Anchor {
|
|||
pub fn bias_right(&self, snapshot: &MultiBufferSnapshot) -> Anchor {
|
||||
if self.text_anchor.bias != Bias::Right {
|
||||
if let Some(excerpt) = snapshot.excerpt(&self.excerpt_id) {
|
||||
if self.buffer_id == Some(excerpt.buffer_id) {
|
||||
return Self {
|
||||
buffer_id: self.buffer_id,
|
||||
excerpt_id: self.excerpt_id.clone(),
|
||||
text_anchor: self.text_anchor.bias_right(&excerpt.buffer),
|
||||
};
|
||||
}
|
||||
return Self {
|
||||
buffer_id: self.buffer_id,
|
||||
excerpt_id: self.excerpt_id.clone(),
|
||||
text_anchor: self.text_anchor.bias_right(&excerpt.buffer),
|
||||
};
|
||||
}
|
||||
}
|
||||
self.clone()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue