Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Checkpoint
Nathan Sobo4a3a1ad0c35f
diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rsindex 630b062d1fb..8ee99e19af4 100644--- a/crates/editor2/src/element.rs+++ b/crates/editor2/src/element.rs@@ -2455,7 +2455,7 @@ impl Element<Editor> for EditorElement {editor.style = Some(self.style.clone()); // Long-term, we'd like to eliminate this.let dispatch_context = editor.dispatch_context(cx);- cx.with_element_id(cx.view().entity_id(), |global_id, cx| {+ cx.with_element_id(Some(cx.view().entity_id()), |cx| {cx.with_key_dispatch(dispatch_context,Some(editor.focus_handle.clone()),diff --git a/crates/gpui2/src/elements/div.rs b/crates/gpui2/src/elements/div.rsindex 2b411f76091..1d85450c29f 100644--- a/crates/gpui2/src/elements/div.rs+++ b/crates/gpui2/src/elements/div.rs@@ -2,7 +2,7 @@ use std::fmt::Debug;use crate::{point, AnyElement, BorrowWindow, Bounds, Component, Element, ElementId, ElementInteractivity,- FocusHandle, FocusListeners, Focusable, FocusableKeyDispatch, GlobalElementId, GroupBounds,+ FocusHandle, FocusListeners, Focusable, FocusableKeyDispatch, GroupBounds,InteractiveElementState, KeyContext, KeyDispatch, LayoutId, NonFocusableKeyDispatch, Overflow,ParentElement, Pixels, Point, SharedString, StatefulInteractive, StatefulInteractivity,StatelessInteractive, StatelessInteractivity, Style, StyleRefinement, Styled, ViewContext,@@ -93,18 +93,6 @@ whereself}- fn with_element_id<R>(- &mut self,- cx: &mut ViewContext<V>,- f: impl FnOnce(&mut Self, Option<GlobalElementId>, &mut ViewContext<V>) -> R,- ) -> R {- if let Some(id) = self.id() {- cx.with_element_id(id, |global_id, cx| f(self, Some(global_id), cx))- } else {- f(self, None, cx)- }- }-pub fn compute_style(&self,bounds: Bounds<Pixels>,@@ -229,14 +217,14 @@ wherecx: &mut ViewContext<V>,) -> Self::ElementState {let mut element_state = element_state.unwrap_or_default();- self.with_element_id(cx, |this, _global_id, cx| {- this.key_dispatch.initialize(+ cx.with_element_id(self.id(), |cx| {+ self.key_dispatch.initialize(element_state.focus_handle.take(),cx,|focus_handle, cx| {- this.interactivity.initialize(cx);+ self.interactivity.initialize(cx);element_state.focus_handle = focus_handle;- for child in &mut this.children {+ for child in &mut self.children {child.initialize(view_state, cx);}},@@ -253,8 +241,8 @@ where) -> LayoutId {let style = self.compute_style(Bounds::default(), element_state, cx);style.apply_text_style(cx, |cx| {- self.with_element_id(cx, |this, _global_id, cx| {- let layout_ids = this+ cx.with_element_id(self.id(), |cx| {+ let layout_ids = self.children.iter_mut().map(|child| child.layout(view_state, cx))@@ -272,8 +260,8 @@ whereelement_state: &mut Self::ElementState,cx: &mut ViewContext<V>,) {- self.with_element_id(cx, |this, _global_id, cx| {- let style = this.compute_style(bounds, element_state, cx);+ cx.with_element_id(self.id(), |cx| {+ let style = self.compute_style(bounds, element_state, cx);if style.visibility == Visibility::Hidden {return;}@@ -285,7 +273,7 @@ where}}- if let Some(group) = this.group.clone() {+ if let Some(group) = self.group.clone() {GroupBounds::push(group, bounds, cx);}@@ -308,8 +296,8 @@ wherecx.with_z_index(z_index, |cx| {cx.with_z_index(0, |cx| {style.paint(bounds, cx);- this.key_dispatch.paint(bounds, cx);- this.interactivity.handle_events(+ self.key_dispatch.paint(bounds, cx);+ self.interactivity.handle_events(bounds,content_size,style.overflow,@@ -322,7 +310,7 @@ wherestyle.apply_overflow(bounds, cx, |cx| {let scroll_offset = element_state.interactive.scroll_offset();cx.with_element_offset(scroll_offset.unwrap_or_default(), |cx| {- for child in &mut this.children {+ for child in &mut self.children {child.paint(view_state, cx);}});@@ -331,7 +319,7 @@ where});});- if let Some(group) = this.group.as_ref() {+ if let Some(group) = self.group.as_ref() {GroupBounds::pop(group, cx);}})diff --git a/crates/gpui2/src/elements/node.rs b/crates/gpui2/src/elements/node.rsindex d5bfd63647c..f3d2b38dfb1 100644--- a/crates/gpui2/src/elements/node.rs+++ b/crates/gpui2/src/elements/node.rs@@ -1008,6 +1008,8 @@ whereGroupBounds::push(group, bounds, cx);}+ todo!();+ // cx.with_element_id(self.i, f);cx.with_key_dispatch(self.key_context.clone(),self.tracked_focus_handle.clone(),diff --git a/crates/gpui2/src/view.rs b/crates/gpui2/src/view.rsindex d12d84f43b4..3299ce7d45e 100644--- a/crates/gpui2/src/view.rs+++ b/crates/gpui2/src/view.rs@@ -286,7 +286,7 @@ mod any_view {use std::any::Any;pub(crate) fn initialize<V: Render>(view: &AnyView, cx: &mut WindowContext) -> Box<dyn Any> {- cx.with_element_id(view.model.entity_id, |_, cx| {+ cx.with_element_id(Some(view.model.entity_id), |cx| {let view = view.clone().downcast::<V>().unwrap();let element = view.update(cx, |view, cx| {let mut element = AnyElement::new(view.render(cx));@@ -302,7 +302,7 @@ mod any_view {element: &mut Box<dyn Any>,cx: &mut WindowContext,) -> LayoutId {- cx.with_element_id(view.model.entity_id, |_, cx| {+ cx.with_element_id(Some(view.model.entity_id), |cx| {let view = view.clone().downcast::<V>().unwrap();let element = element.downcast_mut::<AnyElement<V>>().unwrap();view.update(cx, |view, cx| element.layout(view, cx))@@ -314,7 +314,7 @@ mod any_view {element: &mut Box<dyn Any>,cx: &mut WindowContext,) {- cx.with_element_id(view.model.entity_id, |_, cx| {+ cx.with_element_id(Some(view.model.entity_id), |cx| {let view = view.clone().downcast::<V>().unwrap();let element = element.downcast_mut::<AnyElement<V>>().unwrap();view.update(cx, |view, cx| element.paint(view, cx))diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rsindex edda71f13fe..c5d794aa3d8 100644--- a/crates/gpui2/src/window.rs+++ b/crates/gpui2/src/window.rs@@ -1537,16 +1537,19 @@ pub trait BorrowWindow: BorrowMut<Window> + BorrowMut<AppContext> {/// used to associate state with identified elements across separate frames.fn with_element_id<R>(&mut self,- id: impl Into<ElementId>,- f: impl FnOnce(GlobalElementId, &mut Self) -> R,+ id: Option<impl Into<ElementId>>,+ f: impl FnOnce(&mut Self) -> R,) -> R {- let window = self.window_mut();- window.element_id_stack.push(id.into());- let global_id = window.element_id_stack.clone();- let result = f(global_id, self);- let window: &mut Window = self.borrow_mut();- window.element_id_stack.pop();- result+ if let Some(id) = id.map(Into::into) {+ let window = self.window_mut();+ window.element_id_stack.push(id.into());+ let result = f(self);+ let window: &mut Window = self.borrow_mut();+ window.element_id_stack.pop();+ result+ } else {+ f(self)+ }}/// Invoke the given function with the given content mask after intersecting it@@ -1613,7 +1616,9 @@ pub trait BorrowWindow: BorrowMut<Window> + BorrowMut<AppContext> {whereS: 'static,{- self.with_element_id(id, |global_id, cx| {+ self.with_element_id(Some(id), |cx| {+ let global_id = cx.window().element_id_stack.clone();+if let Some(any) = cx.window_mut().current_frame