Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Checkpoint
Nathan Sobo93c233b1cf44
diff --git a/crates/gpui3/src/elements/div.rs b/crates/gpui3/src/elements/div.rsindex ee0bb22779e..bbe45be8a12 100644--- a/crates/gpui3/src/elements/div.rs+++ b/crates/gpui3/src/elements/div.rs@@ -1,5 +1,5 @@use crate::{- AnyElement, Bounds, Element, ElementId, IdentifiedElement, Interactive, LayoutId,+ AnyElement, BorrowWindow, Bounds, Element, ElementId, IdentifiedElement, Interactive, LayoutId,MouseEventListeners, Overflow, ParentElement, Pixels, Point, Refineable, RefinementCascade,Style, Styled, ViewContext,};@@ -44,7 +44,9 @@ impl<S: 'static + Send + Sync, Marker: 'static + Send + Sync> Element for Div<S,cx: &mut ViewContext<S>,) -> (LayoutId, Self::ElementState) {let style = self.computed_style();- let child_layout_ids = style.apply_text_style(cx, |cx| self.layout_children(view, cx));+ let child_layout_ids = style.apply_text_style(cx, |cx| {+ self.with_element_id(cx, |this, cx| this.layout_children(view, cx))+ });let layout_id = cx.request_layout(style.into(), child_layout_ids.clone());(layout_id, ())}@@ -60,11 +62,14 @@ impl<S: 'static + Send + Sync, Marker: 'static + Send + Sync> Element for Div<S,cx.stack(0, |cx| style.paint(bounds, cx));let overflow = &style.overflow;+style.apply_text_style(cx, |cx| {cx.stack(1, |cx| {style.apply_overflow(bounds, cx, |cx| {- self.listeners.paint(bounds, cx);- self.paint_children(overflow, state, cx)+ self.with_element_id(cx, |this, cx| {+ this.listeners.paint(bounds, cx);+ this.paint_children(overflow, state, cx)+ });})})});@@ -157,6 +162,18 @@ wherechild.paint(state, Some(scroll_offset), cx);}}++ fn with_element_id<R>(+ &mut self,+ cx: &mut ViewContext<S>,+ f: impl FnOnce(&mut Self, &mut ViewContext<S>) -> R,+ ) -> R {+ if let Some(element_id) = self.element_id() {+ cx.with_element_id(element_id, |cx| f(self, cx))+ } else {+ f(self, cx)+ }+ }}impl<V: 'static + Send + Sync, Marker: 'static + Send + Sync> Styled for Div<V, Marker> {diff --git a/crates/gpui3/src/view.rs b/crates/gpui3/src/view.rsindex 88eeab8aa38..a7db926fc3e 100644--- a/crates/gpui3/src/view.rs+++ b/crates/gpui3/src/view.rs@@ -1,8 +1,8 @@use parking_lot::Mutex;use crate::{- AnyBox, AnyElement, Bounds, Element, Handle, IntoAnyElement, LayoutId, Pixels, ViewContext,- WindowContext,+ AnyBox, AnyElement, BorrowWindow, Bounds, Element, ElementId, Handle, IdentifiedElement,+ IntoAnyElement, LayoutId, Pixels, ViewContext, WindowContext,};use std::{any::Any, marker::PhantomData, sync::Arc};@@ -12,7 +12,7 @@ pub struct View<S: Send + Sync, P> {parent_state_type: PhantomData<P>,}-impl<S: 'static + Send + Sync, P: 'static + Send> View<S, P> {+impl<S: 'static + Send + Sync, P: 'static + Send + Sync> View<S, P> {pub fn into_any(self) -> AnyView<P> {AnyView {view: Arc::new(Mutex::new(self)),@@ -54,7 +54,7 @@ impl<S: 'static + Send + Sync, P: 'static + Send + Sync> Element for View<S, P>type ElementState = AnyElement<S>;fn element_id(&self) -> Option<crate::ElementId> {- None+ Some(ElementId::View(self.state.id))}fn layout(@@ -87,20 +87,26 @@ trait ViewObject: Send + 'static {fn paint(&mut self, bounds: Bounds<Pixels>, element: &mut dyn Any, cx: &mut WindowContext);}-impl<S: Send + Sync + 'static, P: Send + 'static> ViewObject for View<S, P> {+impl<S: Send + Sync + 'static, P: Send + Sync + 'static> IdentifiedElement for View<S, P> {}++impl<S: Send + Sync + 'static, P: Send + Sync + 'static> ViewObject for View<S, P> {fn layout(&mut self, cx: &mut WindowContext) -> (LayoutId, AnyBox) {- self.state.update(cx, |state, cx| {- let mut element = (self.render)(state, cx);- let layout_id = element.layout(state, cx);- let element = Box::new(element) as AnyBox;- (layout_id, element)+ cx.with_element_id(IdentifiedElement::element_id(self), |cx| {+ self.state.update(cx, |state, cx| {+ let mut element = (self.render)(state, cx);+ let layout_id = element.layout(state, cx);+ let element = Box::new(element) as AnyBox;+ (layout_id, element)+ })})}fn paint(&mut self, _: Bounds<Pixels>, element: &mut dyn Any, cx: &mut WindowContext) {- self.state.update(cx, |state, cx| {- let element = element.downcast_mut::<AnyElement<S>>().unwrap();- element.paint(state, None, cx);+ cx.with_element_id(IdentifiedElement::element_id(self), |cx| {+ self.state.update(cx, |state, cx| {+ let element = element.downcast_mut::<AnyElement<S>>().unwrap();+ element.paint(state, None, cx);+ });});}}diff --git a/crates/gpui3/src/window.rs b/crates/gpui3/src/window.rsindex df0d8cb1da4..1f1f87afac3 100644--- a/crates/gpui3/src/window.rs+++ b/crates/gpui3/src/window.rs@@ -21,7 +21,7 @@ use std::{mem,sync::Arc,};-use util::{arc_cow::ArcCow, ResultExt};+use util::ResultExt;#[derive(Deref, DerefMut, Ord, PartialOrd, Eq, PartialEq, Clone, Default)]pub struct StackingOrder(pub(crate) SmallVec<[u32; 16]>);@@ -1110,22 +1110,19 @@ impl From<SmallVec<[u32; 16]>> for StackingOrder {}#[derive(Clone, Debug, Eq, PartialEq, Hash)]-pub struct ElementId(ArcCow<'static, [u8]>);+pub enum ElementId {+ View(EntityId),+ Number(usize),+}impl From<usize> for ElementId {fn from(id: usize) -> Self {- Self(id.to_ne_bytes().to_vec().into())+ ElementId::Number(id)}}impl From<i32> for ElementId {fn from(id: i32) -> Self {- Self(id.to_ne_bytes().to_vec().into())- }-}--impl From<&'static str> for ElementId {- fn from(id: &'static str) -> Self {- Self(id.into())+ Self::Number(id as usize)}}diff --git a/crates/storybook2/src/workspace.rs b/crates/storybook2/src/workspace.rsindex fd48cea0091..e91e267f067 100644--- a/crates/storybook2/src/workspace.rs+++ b/crates/storybook2/src/workspace.rs@@ -47,7 +47,8 @@ impl Workspace {.flex_row().overflow_hidden().child(self.left_panel.clone())- .child(div().h_full().flex_1()), // .child(self.right_panel.clone()),+ .child(div().h_full().flex_1())+ .child(self.right_panel.clone()),).child(statusbar::statusbar(cx))})