agent: Only show expand message editor when focused on it (#29595)

Danilo Leal created

Simplifying the UI as much as possible.

Release Notes:

- N/A

Change summary

crates/agent/src/message_editor.rs | 54 ++++++++++++++++---------------
1 file changed, 28 insertions(+), 26 deletions(-)

Detailed changes

crates/agent/src/message_editor.rs 🔗

@@ -495,32 +495,34 @@ impl MessageEditor {
                     .items_start()
                     .justify_between()
                     .child(self.context_strip.clone())
-                    .child(
-                        IconButton::new("toggle-height", expand_icon)
-                            .icon_size(IconSize::XSmall)
-                            .icon_color(Color::Muted)
-                            .tooltip({
-                                let focus_handle = focus_handle.clone();
-                                move |window, cx| {
-                                    let expand_label = if is_editor_expanded {
-                                        "Minimize Message Editor".to_string()
-                                    } else {
-                                        "Expand Message Editor".to_string()
-                                    };
-
-                                    Tooltip::for_action_in(
-                                        expand_label,
-                                        &ExpandMessageEditor,
-                                        &focus_handle,
-                                        window,
-                                        cx,
-                                    )
-                                }
-                            })
-                            .on_click(cx.listener(|_, _, window, cx| {
-                                window.dispatch_action(Box::new(ExpandMessageEditor), cx);
-                            })),
-                    ),
+                    .when(focus_handle.is_focused(window), |this| {
+                        this.child(
+                            IconButton::new("toggle-height", expand_icon)
+                                .icon_size(IconSize::XSmall)
+                                .icon_color(Color::Muted)
+                                .tooltip({
+                                    let focus_handle = focus_handle.clone();
+                                    move |window, cx| {
+                                        let expand_label = if is_editor_expanded {
+                                            "Minimize Message Editor".to_string()
+                                        } else {
+                                            "Expand Message Editor".to_string()
+                                        };
+
+                                        Tooltip::for_action_in(
+                                            expand_label,
+                                            &ExpandMessageEditor,
+                                            &focus_handle,
+                                            window,
+                                            cx,
+                                        )
+                                    }
+                                })
+                                .on_click(cx.listener(|_, _, window, cx| {
+                                    window.dispatch_action(Box::new(ExpandMessageEditor), cx);
+                                })),
+                        )
+                    }),
             )
             .child(
                 v_flex()