agent_ui: Fix message editor stealing focus from other panels (#47321)

Fabian Szabo created

Closes https://github.com/zed-industries/zed/issues/41278,
https://github.com/zed-industries/zed/issues/45576,
https://github.com/zed-industries/zed/issues/46513

Release Notes:

- Fixed message editor stealing focus (so the "Open Recent Project"
modal stays open)

This issue has been driving me insane haha.


_Note: This is my first code contribution to this project. Please be
kind and let me know if I have missed something. I tested this fix on my
machine and it works. Tests are passing on my device. I have agreed to
the Zed Contributor License and Feedback Agreement with my Zed Account
that's linked to the same email as this GitHub account._

Change summary

crates/agent_ui/src/acp/thread_view.rs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

Detailed changes

crates/agent_ui/src/acp/thread_view.rs 🔗

@@ -889,7 +889,9 @@ impl AcpThreadView {
                             })
                         });
 
-                        this.message_editor.focus_handle(cx).focus(window, cx);
+                        if this.focus_handle.contains_focused(window, cx) {
+                            this.message_editor.focus_handle(cx).focus(window, cx);
+                        }
 
                         cx.notify();
                     }