Always `sync` before clearing or removing excerpts from `MultiBuffer`

Antonio Scandurra created

We don't have any test that proves this is needed but seems good nonetheless.

Change summary

crates/editor/src/multi_buffer.rs | 2 ++
1 file changed, 2 insertions(+)

Detailed changes

crates/editor/src/multi_buffer.rs 🔗

@@ -772,6 +772,7 @@ impl MultiBuffer {
     }
 
     pub fn clear(&mut self, cx: &mut ModelContext<Self>) {
+        self.sync(cx);
         self.buffers.borrow_mut().clear();
         let mut snapshot = self.snapshot.borrow_mut();
         let prev_len = snapshot.len();
@@ -853,6 +854,7 @@ impl MultiBuffer {
         excerpt_ids: impl IntoIterator<Item = &'a ExcerptId>,
         cx: &mut ModelContext<Self>,
     ) {
+        self.sync(cx);
         let mut buffers = self.buffers.borrow_mut();
         let mut snapshot = self.snapshot.borrow_mut();
         let mut new_excerpts = SumTree::new();