Reuse views when moving between diagnostic view and editors
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
ea263822fa
commit
ce6f3d7f3e
6 changed files with 103 additions and 21 deletions
|
@ -3097,14 +3097,39 @@ impl Drop for AnyViewHandle {
|
|||
|
||||
pub struct AnyModelHandle {
|
||||
model_id: usize,
|
||||
model_type: TypeId,
|
||||
ref_counts: Arc<Mutex<RefCounts>>,
|
||||
}
|
||||
|
||||
impl AnyModelHandle {
|
||||
pub fn downcast<T: Entity>(self) -> Option<ModelHandle<T>> {
|
||||
if self.is::<T>() {
|
||||
let result = Some(ModelHandle {
|
||||
model_id: self.model_id,
|
||||
model_type: PhantomData,
|
||||
ref_counts: self.ref_counts.clone(),
|
||||
});
|
||||
unsafe {
|
||||
Arc::decrement_strong_count(&self.ref_counts);
|
||||
}
|
||||
std::mem::forget(self);
|
||||
result
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is<T: Entity>(&self) -> bool {
|
||||
self.model_type == TypeId::of::<T>()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Entity> From<ModelHandle<T>> for AnyModelHandle {
|
||||
fn from(handle: ModelHandle<T>) -> Self {
|
||||
handle.ref_counts.lock().inc_model(handle.model_id);
|
||||
Self {
|
||||
model_id: handle.model_id,
|
||||
model_type: TypeId::of::<T>(),
|
||||
ref_counts: handle.ref_counts.clone(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue