panics (#7793)
Release Notes: - Fix a panic in rename ([#7509](https://github.com/zed-industries/zed/issues/7509)). --------- Co-authored-by: Max <max@zed.dev>
This commit is contained in:
parent
855acb948c
commit
65a1938e52
2 changed files with 17 additions and 12 deletions
|
@ -7660,8 +7660,9 @@ impl Editor {
|
||||||
let snapshot = cursor_buffer.read(cx).snapshot();
|
let snapshot = cursor_buffer.read(cx).snapshot();
|
||||||
let cursor_buffer_offset = cursor_buffer_position.to_offset(&snapshot);
|
let cursor_buffer_offset = cursor_buffer_position.to_offset(&snapshot);
|
||||||
let prepare_rename = project.update(cx, |project, cx| {
|
let prepare_rename = project.update(cx, |project, cx| {
|
||||||
project.prepare_rename(cursor_buffer, cursor_buffer_offset, cx)
|
project.prepare_rename(cursor_buffer.clone(), cursor_buffer_offset, cx)
|
||||||
});
|
});
|
||||||
|
drop(snapshot);
|
||||||
|
|
||||||
Some(cx.spawn(|this, mut cx| async move {
|
Some(cx.spawn(|this, mut cx| async move {
|
||||||
let rename_range = if let Some(range) = prepare_rename.await? {
|
let rename_range = if let Some(range) = prepare_rename.await? {
|
||||||
|
@ -7681,11 +7682,12 @@ impl Editor {
|
||||||
})?
|
})?
|
||||||
};
|
};
|
||||||
if let Some(rename_range) = rename_range {
|
if let Some(rename_range) = rename_range {
|
||||||
let rename_buffer_range = rename_range.to_offset(&snapshot);
|
|
||||||
let cursor_offset_in_rename_range =
|
|
||||||
cursor_buffer_offset.saturating_sub(rename_buffer_range.start);
|
|
||||||
|
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
|
let snapshot = cursor_buffer.read(cx).snapshot();
|
||||||
|
let rename_buffer_range = rename_range.to_offset(&snapshot);
|
||||||
|
let cursor_offset_in_rename_range =
|
||||||
|
cursor_buffer_offset.saturating_sub(rename_buffer_range.start);
|
||||||
|
|
||||||
this.take_rename(false, cx);
|
this.take_rename(false, cx);
|
||||||
let buffer = this.buffer.read(cx).read(cx);
|
let buffer = this.buffer.read(cx).read(cx);
|
||||||
let cursor_offset = selection.head().to_offset(&buffer);
|
let cursor_offset = selection.head().to_offset(&buffer);
|
||||||
|
|
|
@ -50,7 +50,6 @@ pub struct ExcerptId(usize);
|
||||||
pub struct MultiBuffer {
|
pub struct MultiBuffer {
|
||||||
snapshot: RefCell<MultiBufferSnapshot>,
|
snapshot: RefCell<MultiBufferSnapshot>,
|
||||||
buffers: RefCell<HashMap<BufferId, BufferState>>,
|
buffers: RefCell<HashMap<BufferId, BufferState>>,
|
||||||
next_excerpt_id: usize,
|
|
||||||
subscriptions: Topic,
|
subscriptions: Topic,
|
||||||
singleton: bool,
|
singleton: bool,
|
||||||
replica_id: ReplicaId,
|
replica_id: ReplicaId,
|
||||||
|
@ -232,7 +231,6 @@ impl MultiBuffer {
|
||||||
Self {
|
Self {
|
||||||
snapshot: Default::default(),
|
snapshot: Default::default(),
|
||||||
buffers: Default::default(),
|
buffers: Default::default(),
|
||||||
next_excerpt_id: 1,
|
|
||||||
subscriptions: Default::default(),
|
subscriptions: Default::default(),
|
||||||
singleton: false,
|
singleton: false,
|
||||||
capability,
|
capability,
|
||||||
|
@ -272,7 +270,6 @@ impl MultiBuffer {
|
||||||
Self {
|
Self {
|
||||||
snapshot: RefCell::new(self.snapshot.borrow().clone()),
|
snapshot: RefCell::new(self.snapshot.borrow().clone()),
|
||||||
buffers: RefCell::new(buffers),
|
buffers: RefCell::new(buffers),
|
||||||
next_excerpt_id: 1,
|
|
||||||
subscriptions: Default::default(),
|
subscriptions: Default::default(),
|
||||||
singleton: self.singleton,
|
singleton: self.singleton,
|
||||||
capability: self.capability,
|
capability: self.capability,
|
||||||
|
@ -993,7 +990,12 @@ impl MultiBuffer {
|
||||||
O: text::ToOffset,
|
O: text::ToOffset,
|
||||||
{
|
{
|
||||||
let mut ids = Vec::new();
|
let mut ids = Vec::new();
|
||||||
let mut next_excerpt_id = self.next_excerpt_id;
|
let mut next_excerpt_id =
|
||||||
|
if let Some(last_entry) = self.snapshot.borrow().excerpt_ids.last() {
|
||||||
|
last_entry.id.0 + 1
|
||||||
|
} else {
|
||||||
|
1
|
||||||
|
};
|
||||||
self.insert_excerpts_with_ids_after(
|
self.insert_excerpts_with_ids_after(
|
||||||
prev_excerpt_id,
|
prev_excerpt_id,
|
||||||
buffer,
|
buffer,
|
||||||
|
@ -1079,9 +1081,6 @@ impl MultiBuffer {
|
||||||
..buffer_snapshot.anchor_after(&primary.end)
|
..buffer_snapshot.anchor_after(&primary.end)
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
if id.0 >= self.next_excerpt_id {
|
|
||||||
self.next_excerpt_id = id.0 + 1;
|
|
||||||
}
|
|
||||||
excerpts.push((id, range.clone()));
|
excerpts.push((id, range.clone()));
|
||||||
let excerpt = Excerpt::new(
|
let excerpt = Excerpt::new(
|
||||||
id,
|
id,
|
||||||
|
@ -1093,6 +1092,10 @@ impl MultiBuffer {
|
||||||
);
|
);
|
||||||
new_excerpts.push(excerpt, &());
|
new_excerpts.push(excerpt, &());
|
||||||
prev_locator = locator.clone();
|
prev_locator = locator.clone();
|
||||||
|
|
||||||
|
if let Some(last_mapping_entry) = new_excerpt_ids.last() {
|
||||||
|
assert!(id > last_mapping_entry.id, "excerpt ids must be increasing");
|
||||||
|
}
|
||||||
new_excerpt_ids.push(ExcerptIdMapping { id, locator }, &());
|
new_excerpt_ids.push(ExcerptIdMapping { id, locator }, &());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue