Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix gpui2 bugs

Max Brunsfeld8bc20714144f
diff --git a/crates/gpui2/src/app.rs b/crates/gpui2/src/app.rs
index 75f202e7106..35efe84e485 100644
--- a/crates/gpui2/src/app.rs
+++ b/crates/gpui2/src/app.rs
@@ -403,7 +403,7 @@ impl AppContext {
fn apply_emit_effect(&mut self, emitter: EntityId, event: Box<dyn Any>) {
self.event_listeners
.clone()
- .retain(&emitter, |handler| handler(&event, self));
+ .retain(&emitter, |handler| handler(event.as_ref(), self));
}
fn apply_focus_changed_effect(&mut self, window_id: WindowId, focused: Option<FocusId>) {
diff --git a/crates/gpui2/src/app/entity_map.rs b/crates/gpui2/src/app/entity_map.rs
index cf39a2b81f1..04205175903 100644
--- a/crates/gpui2/src/app/entity_map.rs
+++ b/crates/gpui2/src/app/entity_map.rs
@@ -100,10 +100,15 @@ impl EntityMap {
}
pub fn take_dropped(&mut self) -> Vec<(EntityId, AnyBox)> {
- let dropped_entity_ids = mem::take(&mut self.ref_counts.write().dropped_entity_ids);
+ let mut ref_counts = self.ref_counts.write();
+ let dropped_entity_ids = mem::take(&mut ref_counts.dropped_entity_ids);
+
dropped_entity_ids
.into_iter()
- .map(|entity_id| (entity_id, self.entities.remove(entity_id).unwrap()))
+ .map(|entity_id| {
+ ref_counts.counts.remove(entity_id);
+ (entity_id, self.entities.remove(entity_id).unwrap())
+ })
.collect()
}
}
@@ -212,7 +217,6 @@ impl Drop for AnyHandle {
if prev_count == 1 {
// We were the last reference to this entity, so we can remove it.
let mut entity_map = RwLockUpgradableReadGuard::upgrade(entity_map);
- entity_map.counts.remove(self.entity_id);
entity_map.dropped_entity_ids.push(self.entity_id);
}
}
diff --git a/crates/gpui2/src/app/model_context.rs b/crates/gpui2/src/app/model_context.rs
index 6f88bf1aa6c..d81b113b7b6 100644
--- a/crates/gpui2/src/app/model_context.rs
+++ b/crates/gpui2/src/app/model_context.rs
@@ -79,7 +79,7 @@ impl<'a, T: 'static> ModelContext<'a, T> {
self.app.event_listeners.insert(
handle.entity_id,
Box::new(move |event, cx| {
- let event = event.downcast_ref().expect("invalid event type");
+ let event: &E::Event = event.downcast_ref().expect("invalid event type");
if let Some((this, handle)) = this.upgrade().zip(handle.upgrade()) {
this.update(cx, |this, cx| on_event(this, handle, event, cx));
true
diff --git a/crates/gpui2/src/test.rs b/crates/gpui2/src/test.rs
index ffad9aab8bf..3f2697f7e3f 100644
--- a/crates/gpui2/src/test.rs
+++ b/crates/gpui2/src/test.rs
@@ -8,7 +8,7 @@ use std::{
pub fn run_test(
mut num_iterations: u64,
max_retries: usize,
- test_fn: &mut (dyn RefUnwindSafe + Fn(TestDispatcher)),
+ test_fn: &mut (dyn RefUnwindSafe + Fn(TestDispatcher, u64)),
on_fail_fn: Option<fn()>,
_fn_name: String, // todo!("re-enable fn_name")
) {
@@ -28,7 +28,7 @@ pub fn run_test(
}
let result = panic::catch_unwind(|| {
let dispatcher = TestDispatcher::new(StdRng::seed_from_u64(seed));
- test_fn(dispatcher);
+ test_fn(dispatcher, seed);
});
match result {