Detailed changes
@@ -681,7 +681,7 @@ impl MessageEditor {
editor.insert(&mention_text, window, cx);
editor.insert(" ", window, cx);
- (*excerpt_id, text_anchor, mention_text.len())
+ (excerpt_id, text_anchor, mention_text.len())
});
let Some((crease_id, tx)) = insert_crease_for_mention(
@@ -951,7 +951,7 @@ impl MessageEditor {
editor.insert(&mention_text, window, cx);
editor.insert(" ", window, cx);
- (*excerpt_id, text_anchor, mention_text.len())
+ (excerpt_id, text_anchor, mention_text.len())
});
let Some((crease_id, tx)) = insert_crease_for_mention(
@@ -5634,12 +5634,17 @@ impl AcpThreadView {
};
active_editor.update_in(cx, |editor, window, cx| {
- let multibuffer = editor.buffer().read(cx);
- let buffer = multibuffer.as_singleton();
- if agent_location.buffer.upgrade() == buffer {
- let excerpt_id = multibuffer.excerpt_ids().first().cloned();
- let anchor =
- editor::Anchor::in_buffer(excerpt_id.unwrap(), agent_location.position);
+ let singleton = editor
+ .buffer()
+ .read(cx)
+ .read(cx)
+ .as_singleton()
+ .map(|(a, b, _)| (a, b));
+ if let Some((excerpt_id, buffer_id)) = singleton
+ && let Some(agent_buffer) = agent_location.buffer.upgrade()
+ && agent_buffer.read(cx).remote_id() == buffer_id
+ {
+ let anchor = editor::Anchor::in_buffer(excerpt_id, agent_location.position);
editor.change_selections(Default::default(), window, cx, |selections| {
selections.select_anchor_ranges([anchor..anchor]);
})
@@ -665,9 +665,9 @@ pub(crate) async fn insert_images_as_context(
let text_anchor = cursor_anchor.bias_left(&buffer_snapshot);
let multibuffer_anchor = snapshot
.buffer_snapshot()
- .anchor_in_excerpt(*excerpt_id, text_anchor);
+ .anchor_in_excerpt(excerpt_id, text_anchor);
editor.insert(&format!("{replacement_text} "), window, cx);
- (*excerpt_id, text_anchor, multibuffer_anchor)
+ (excerpt_id, text_anchor, multibuffer_anchor)
})
.ok()
else {
@@ -687,7 +687,7 @@ impl TextThreadEditor {
TextThreadEvent::ParsedSlashCommandsUpdated { removed, updated } => {
self.editor.update(cx, |editor, cx| {
let buffer = editor.buffer().read(cx).snapshot(cx);
- let (&excerpt_id, _, _) = buffer.as_singleton().unwrap();
+ let (excerpt_id, _, _) = buffer.as_singleton().unwrap();
editor.remove_creases(
removed
@@ -810,8 +810,7 @@ impl TextThreadEditor {
{
if let InvokedSlashCommandStatus::Finished = invoked_slash_command.status {
let buffer = editor.buffer().read(cx).snapshot(cx);
- let (&excerpt_id, _buffer_id, _buffer_snapshot) =
- buffer.as_singleton().unwrap();
+ let (excerpt_id, _buffer_id, _buffer_snapshot) = buffer.as_singleton().unwrap();
let range = buffer
.anchor_range_in_excerpt(excerpt_id, invoked_slash_command.range.clone())
@@ -831,8 +830,7 @@ impl TextThreadEditor {
self.invoked_slash_command_creases.entry(command_id)
{
let buffer = editor.buffer().read(cx).snapshot(cx);
- let (&excerpt_id, _buffer_id, _buffer_snapshot) =
- buffer.as_singleton().unwrap();
+ let (excerpt_id, _buffer_id, _buffer_snapshot) = buffer.as_singleton().unwrap();
let context = self.text_thread.downgrade();
let range = buffer
.anchor_range_in_excerpt(excerpt_id, invoked_slash_command.range.clone())
@@ -872,7 +870,7 @@ impl TextThreadEditor {
) -> Vec<CreaseId> {
self.editor.update(cx, |editor, cx| {
let buffer = editor.buffer().read(cx).snapshot(cx);
- let excerpt_id = *buffer.as_singleton().unwrap().0;
+ let excerpt_id = buffer.as_singleton().unwrap().0;
let mut buffer_rows_to_fold = BTreeSet::new();
let mut creases = Vec::new();
for (section, status) in sections {
@@ -921,7 +919,7 @@ impl TextThreadEditor {
) {
self.editor.update(cx, |editor, cx| {
let buffer = editor.buffer().read(cx).snapshot(cx);
- let excerpt_id = *buffer.as_singleton().unwrap().0;
+ let excerpt_id = buffer.as_singleton().unwrap().0;
let mut buffer_rows_to_fold = BTreeSet::new();
let mut creases = Vec::new();
for section in sections {
@@ -1052,7 +1050,7 @@ impl TextThreadEditor {
self.editor.update(cx, |editor, cx| {
let buffer = editor.buffer().read(cx).snapshot(cx);
- let excerpt_id = *buffer.as_singleton().unwrap().0;
+ let excerpt_id = buffer.as_singleton().unwrap().0;
let mut old_blocks = std::mem::take(&mut self.blocks);
let mut blocks_to_remove: HashMap<_, _> = old_blocks
.iter()
@@ -2028,7 +2026,7 @@ impl TextThreadEditor {
fn update_image_blocks(&mut self, cx: &mut Context<Self>) {
self.editor.update(cx, |editor, cx| {
let buffer = editor.buffer().read(cx).snapshot(cx);
- let excerpt_id = *buffer.as_singleton().unwrap().0;
+ let excerpt_id = buffer.as_singleton().unwrap().0;
let old_blocks = std::mem::take(&mut self.image_blocks);
let new_blocks = self
.text_thread
@@ -2000,7 +2000,6 @@ impl Editor {
return;
};
let buffer = buffer.clone();
- let &excerpt_id = excerpt_id;
let buffer_visible_start = scroll_anchor.text_anchor.to_point(&buffer);
let max_row = buffer.max_point().row;
@@ -24624,7 +24623,7 @@ impl Editor {
};
let nav_history = editor.nav_history.take();
let multibuffer_snapshot = editor.buffer().read(cx).snapshot(cx);
- let Some((&excerpt_id, _, buffer_snapshot)) =
+ let Some((excerpt_id, _, buffer_snapshot)) =
multibuffer_snapshot.as_singleton()
else {
return;
@@ -1421,7 +1421,7 @@ impl ProjectItem for Editor {
}
let (top_row, offset) = restoration_data.scroll_position;
let anchor =
- Anchor::in_buffer(*excerpt_id, snapshot.anchor_before(Point::new(top_row, 0)));
+ Anchor::in_buffer(excerpt_id, snapshot.anchor_before(Point::new(top_row, 0)));
editor.set_scroll_anchor(ScrollAnchor { anchor, offset }, window, cx);
}
@@ -4688,12 +4688,12 @@ impl MultiBufferSnapshot {
self.singleton
}
- pub fn as_singleton(&self) -> Option<(&ExcerptId, BufferId, &BufferSnapshot)> {
+ pub fn as_singleton(&self) -> Option<(ExcerptId, BufferId, &BufferSnapshot)> {
if self.singleton {
self.excerpts
.iter()
.next()
- .map(|e| (&e.id, e.buffer_id, &*e.buffer))
+ .map(|e| (e.id, e.buffer_id, &*e.buffer))
} else {
None
}
@@ -5822,7 +5822,7 @@ impl MultiBufferSnapshot {
pub fn as_singleton_anchor(&self, text_anchor: text::Anchor) -> Option<Anchor> {
let (excerpt, buffer, _) = self.as_singleton()?;
if text_anchor.buffer_id.is_none_or(|id| id == buffer) {
- Some(Anchor::in_buffer(*excerpt, text_anchor))
+ Some(Anchor::in_buffer(excerpt, text_anchor))
} else {
None
}
@@ -6750,17 +6750,17 @@ impl MultiBufferSnapshot {
.flat_map(|item| {
Some(OutlineItem {
depth: item.depth,
- range: self.anchor_range_in_excerpt(*excerpt_id, item.range)?,
+ range: self.anchor_range_in_excerpt(excerpt_id, item.range)?,
source_range_for_text: self
- .anchor_range_in_excerpt(*excerpt_id, item.source_range_for_text)?,
+ .anchor_range_in_excerpt(excerpt_id, item.source_range_for_text)?,
text: item.text,
highlight_ranges: item.highlight_ranges,
name_ranges: item.name_ranges,
body_range: item.body_range.and_then(|body_range| {
- self.anchor_range_in_excerpt(*excerpt_id, body_range)
+ self.anchor_range_in_excerpt(excerpt_id, body_range)
}),
annotation_range: item.annotation_range.and_then(|annotation_range| {
- self.anchor_range_in_excerpt(*excerpt_id, annotation_range)
+ self.anchor_range_in_excerpt(excerpt_id, annotation_range)
}),
})
})
@@ -82,7 +82,6 @@ fn outline_for_editor(
) -> Option<Task<Vec<OutlineItem<Anchor>>>> {
let multibuffer = editor.read(cx).buffer().read(cx).snapshot(cx);
let (excerpt_id, _, buffer_snapshot) = multibuffer.as_singleton()?;
- let excerpt_id = *excerpt_id;
let buffer_id = buffer_snapshot.remote_id();
let task = editor.update(cx, |editor, cx| editor.buffer_outline_items(buffer_id, cx));