Return an element directly from PanelHandle::flex_content

Max Brunsfeld and Eric Holk created

Co-authored-by: Eric Holk <eric@zed.dev>

Change summary

crates/agent_ui/src/agent_panel.rs |  6 +-----
crates/workspace/src/dock.rs       | 25 ++++++-------------------
crates/workspace/src/pane_group.rs | 15 +++++++--------
3 files changed, 14 insertions(+), 32 deletions(-)

Detailed changes

crates/agent_ui/src/agent_panel.rs 🔗

@@ -3706,11 +3706,7 @@ impl AgentPanel {
             let is_agent_selected = move |agent_type: AgentType| selected_agent == agent_type;
 
             let workspace = self.workspace.clone();
-            let is_via_collab = workspace
-                .update(cx, |workspace, cx| {
-                    workspace.project().read(cx).is_via_collab()
-                })
-                .unwrap_or_default();
+            let is_via_collab = self.project.read(cx).is_via_collab();
 
             let focus_handle = focus_handle.clone();
             let agent_server_store = agent_server_store;

crates/workspace/src/dock.rs 🔗

@@ -96,7 +96,7 @@ pub trait PanelHandle: Send + Sync {
     fn to_any(&self) -> AnyView;
     fn activation_priority(&self, cx: &App) -> u32;
     fn enabled(&self, cx: &App) -> bool;
-    fn flex_content(&self, window: &Window, cx: &mut App) -> Option<AnyView>;
+    fn flex_content(&self, window: &mut Window, cx: &mut App) -> Option<AnyElement>;
     fn has_flex_content(&self, window: &Window, cx: &App) -> bool;
     fn has_panel_content(&self, window: &Window, cx: &App) -> bool;
     fn move_to_next_position(&self, window: &mut Window, cx: &mut App) {
@@ -204,11 +204,14 @@ where
         self.read(cx).enabled(cx)
     }
 
-    fn flex_content(&self, window: &Window, cx: &mut App) -> Option<AnyView> {
+    fn flex_content(&self, window: &mut Window, cx: &mut App) -> Option<AnyElement> {
         if !self.read(cx).has_flex_content(window, cx) {
             return None;
         }
-        Some(cx.new(|_| PanelCenterView(self.clone())).into())
+        Some(
+            self.update(cx, |this, cx| this.render_flex_content(window, cx))
+                .unwrap_or_else(|| gpui::Empty.into_any_element()),
+        )
     }
 
     fn has_flex_content(&self, window: &Window, cx: &App) -> bool {
@@ -220,17 +223,6 @@ where
     }
 }
 
-struct PanelCenterView<T: Panel>(Entity<T>);
-
-impl<T: Panel> Render for PanelCenterView<T> {
-    fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
-        self.0.update(cx, |this, cx| {
-            this.render_flex_content(window, cx)
-                .unwrap_or_else(|| gpui::Empty.into_any_element())
-        })
-    }
-}
-
 impl From<&dyn PanelHandle> for AnyView {
     fn from(val: &dyn PanelHandle) -> Self {
         val.to_any()
@@ -732,11 +724,6 @@ impl Dock {
         Some(&entry.panel)
     }
 
-    pub fn visible_panel_flex_element(&self, window: &Window, cx: &mut App) -> Option<AnyView> {
-        let entry = self.visible_entry()?;
-        entry.panel.flex_content(window, cx)
-    }
-
     pub fn active_panel(&self) -> Option<&Arc<dyn PanelHandle>> {
         let panel_entry = self.active_panel_entry()?;
         Some(&panel_entry.panel)

crates/workspace/src/pane_group.rs 🔗

@@ -223,8 +223,8 @@ impl PaneGroup {
     pub fn render(
         &self,
         zoomed: Option<&AnyWeakView>,
-        left_content: Option<AnyView>,
-        right_content: Option<AnyView>,
+        left_content: Option<AnyElement>,
+        right_content: Option<AnyElement>,
         render_cx: &dyn PaneLeaderDecorator,
         window: &mut Window,
         cx: &mut App,
@@ -546,8 +546,8 @@ impl Member {
         &self,
         basis: usize,
         zoomed: Option<&AnyWeakView>,
-        left_content: Option<AnyView>,
-        right_content: Option<AnyView>,
+        left_content: Option<AnyElement>,
+        right_content: Option<AnyElement>,
         pane_group_state: Option<PaneGroupState>,
         render_cx: &dyn PaneLeaderDecorator,
         window: &mut Window,
@@ -1086,8 +1086,8 @@ impl PaneAxis {
         basis: usize,
         zoomed: Option<&AnyWeakView>,
         pane_group_state: Option<PaneGroupState>,
-        left_content: Option<AnyView>,
-        right_content: Option<AnyView>,
+        left_content: Option<AnyElement>,
+        right_content: Option<AnyElement>,
         render_cx: &dyn PaneLeaderDecorator,
         window: &mut Window,
         cx: &mut App,
@@ -1098,7 +1098,6 @@ impl PaneAxis {
         let mut is_leaf_pane = vec![false; self.members.len()];
 
         let rendered_children = left_content
-            .map(|view| view.into_any_element())
             .into_iter()
             .chain(self.members.iter().enumerate().map(|(ix, member)| {
                 match member {
@@ -1129,7 +1128,7 @@ impl PaneAxis {
                 }
                 result.element.into_any_element()
             }))
-            .chain(right_content.map(|view| view.into_any_element()))
+            .chain(right_content)
             .collect::<Vec<_>>();
 
         let element = pane_axis(