Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Preserve stacking order ID order when reusing cached view state
Julia455d5eeb89fc
diff --git a/crates/gpui/src/view.rs b/crates/gpui/src/view.rsindex c6a4d4b52c5..47f2809038d 100644--- a/crates/gpui/src/view.rs+++ b/crates/gpui/src/view.rs@@ -23,6 +23,7 @@ impl<V> Sealed for View<V> {}#[doc(hidden)]pub struct AnyViewState {root_style: Style,+ next_stacking_order_id: u16,cache_key: Option<ViewCacheKey>,element: Option<AnyElement>,}@@ -292,6 +293,7 @@ impl Element for AnyView {let root_style = cx.layout_style(layout_id).unwrap().clone();let state = AnyViewState {root_style,+ next_stacking_order_id: 0,cache_key: None,element: Some(element),};@@ -314,7 +316,7 @@ impl Element for AnyView {&& !cx.window.dirty_views.contains(&self.entity_id())&& !cx.window.refreshing{- cx.reuse_view();+ cx.reuse_view(state.next_stacking_order_id);return;}}@@ -326,6 +328,7 @@ impl Element for AnyView {element.draw(bounds.origin, bounds.size.into(), cx);}+ state.next_stacking_order_id = cx.window.next_frame.next_stacking_order_id;state.cache_key = Some(ViewCacheKey {bounds,stacking_order: cx.stacking_order().clone(),diff --git a/crates/gpui/src/window/element_cx.rs b/crates/gpui/src/window/element_cx.rsindex ceed10671c9..132cc72a5c7 100644--- a/crates/gpui/src/window/element_cx.rs+++ b/crates/gpui/src/window/element_cx.rs@@ -292,7 +292,7 @@ impl<'a> VisualContext for ElementContext<'a> {}impl<'a> ElementContext<'a> {- pub(crate) fn reuse_view(&mut self) {+ pub(crate) fn reuse_view(&mut self, next_stacking_order_id: u16) {let view_id = self.parent_view_id();let grafted_view_ids = self.cx@@ -333,6 +333,9 @@ impl<'a> ElementContext<'a> {self.window.next_frame.requested_cursor_style = Some(style);}}++ debug_assert!(next_stacking_order_id >= self.window.next_frame.next_stacking_order_id);+ self.window.next_frame.next_stacking_order_id = next_stacking_order_id;}pub fn with_text_style<F, R>(&mut self, style: Option<TextStyleRefinement>, f: F) -> R