Remove special case for singleton buffers from MultiBufferSnapshot::anchor_at
(#36524)
This may be responsible for a panic that we've been seeing with increased frequency in agent2 threads. Release Notes: - N/A Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
parent
ec8106d1db
commit
b6722ca3c8
2 changed files with 43 additions and 31 deletions
|
@ -4876,11 +4876,7 @@ impl Editor {
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let position = self.selections.newest_anchor().head();
|
let position = self.selections.newest_anchor().head();
|
||||||
let multibuffer = self.buffer.read(cx);
|
let Some(buffer) = self.buffer.read(cx).buffer_for_anchor(position, cx) else {
|
||||||
let Some(buffer) = position
|
|
||||||
.buffer_id
|
|
||||||
.and_then(|buffer_id| multibuffer.buffer(buffer_id))
|
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5844,7 +5840,7 @@ impl Editor {
|
||||||
multibuffer_anchor.start.to_offset(&snapshot)
|
multibuffer_anchor.start.to_offset(&snapshot)
|
||||||
..multibuffer_anchor.end.to_offset(&snapshot)
|
..multibuffer_anchor.end.to_offset(&snapshot)
|
||||||
};
|
};
|
||||||
if newest_anchor.head().buffer_id != Some(buffer.remote_id()) {
|
if snapshot.buffer_id_for_anchor(newest_anchor.head()) != Some(buffer.remote_id()) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2196,6 +2196,15 @@ impl MultiBuffer {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn buffer_for_anchor(&self, anchor: Anchor, cx: &App) -> Option<Entity<Buffer>> {
|
||||||
|
if let Some(buffer_id) = anchor.buffer_id {
|
||||||
|
self.buffer(buffer_id)
|
||||||
|
} else {
|
||||||
|
let (_, buffer, _) = self.excerpt_containing(anchor, cx)?;
|
||||||
|
Some(buffer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If point is at the end of the buffer, the last excerpt is returned
|
// If point is at the end of the buffer, the last excerpt is returned
|
||||||
pub fn point_to_buffer_offset<T: ToOffset>(
|
pub fn point_to_buffer_offset<T: ToOffset>(
|
||||||
&self,
|
&self,
|
||||||
|
@ -5228,15 +5237,6 @@ impl MultiBufferSnapshot {
|
||||||
excerpt_offset += ExcerptOffset::new(offset_in_transform);
|
excerpt_offset += ExcerptOffset::new(offset_in_transform);
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some((excerpt_id, buffer_id, buffer)) = self.as_singleton() {
|
|
||||||
return Anchor {
|
|
||||||
buffer_id: Some(buffer_id),
|
|
||||||
excerpt_id: *excerpt_id,
|
|
||||||
text_anchor: buffer.anchor_at(excerpt_offset.value, bias),
|
|
||||||
diff_base_anchor,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut excerpts = self
|
let mut excerpts = self
|
||||||
.excerpts
|
.excerpts
|
||||||
.cursor::<Dimensions<ExcerptOffset, Option<ExcerptId>>>(&());
|
.cursor::<Dimensions<ExcerptOffset, Option<ExcerptId>>>(&());
|
||||||
|
@ -5260,10 +5260,17 @@ impl MultiBufferSnapshot {
|
||||||
text_anchor,
|
text_anchor,
|
||||||
diff_base_anchor,
|
diff_base_anchor,
|
||||||
}
|
}
|
||||||
} else if excerpt_offset.is_zero() && bias == Bias::Left {
|
|
||||||
Anchor::min()
|
|
||||||
} else {
|
} else {
|
||||||
Anchor::max()
|
let mut anchor = if excerpt_offset.is_zero() && bias == Bias::Left {
|
||||||
|
Anchor::min()
|
||||||
|
} else {
|
||||||
|
Anchor::max()
|
||||||
|
};
|
||||||
|
// TODO this is a hack, remove it
|
||||||
|
if let Some((excerpt_id, _, _)) = self.as_singleton() {
|
||||||
|
anchor.excerpt_id = *excerpt_id;
|
||||||
|
}
|
||||||
|
anchor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6305,6 +6312,14 @@ impl MultiBufferSnapshot {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn buffer_id_for_anchor(&self, anchor: Anchor) -> Option<BufferId> {
|
||||||
|
if let Some(id) = anchor.buffer_id {
|
||||||
|
return Some(id);
|
||||||
|
}
|
||||||
|
let excerpt = self.excerpt_containing(anchor..anchor)?;
|
||||||
|
Some(excerpt.buffer_id())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn selections_in_range<'a>(
|
pub fn selections_in_range<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
range: &'a Range<Anchor>,
|
range: &'a Range<Anchor>,
|
||||||
|
@ -6983,19 +6998,20 @@ impl Excerpt {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn contains(&self, anchor: &Anchor) -> bool {
|
fn contains(&self, anchor: &Anchor) -> bool {
|
||||||
Some(self.buffer_id) == anchor.buffer_id
|
anchor.buffer_id == None
|
||||||
&& self
|
|| anchor.buffer_id == Some(self.buffer_id)
|
||||||
.range
|
&& self
|
||||||
.context
|
.range
|
||||||
.start
|
.context
|
||||||
.cmp(&anchor.text_anchor, &self.buffer)
|
.start
|
||||||
.is_le()
|
.cmp(&anchor.text_anchor, &self.buffer)
|
||||||
&& self
|
.is_le()
|
||||||
.range
|
&& self
|
||||||
.context
|
.range
|
||||||
.end
|
.context
|
||||||
.cmp(&anchor.text_anchor, &self.buffer)
|
.end
|
||||||
.is_ge()
|
.cmp(&anchor.text_anchor, &self.buffer)
|
||||||
|
.is_ge()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The [`Excerpt`]'s start offset in its [`Buffer`]
|
/// The [`Excerpt`]'s start offset in its [`Buffer`]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue