Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

agent_ui: Close search when hitting escape from message editor (#59705)

Danilo Lealcf93437d6a4d
diff --git a/crates/agent_ui/src/conversation_view/thread_search_bar.rs b/crates/agent_ui/src/conversation_view/thread_search_bar.rs
index bf09c33ae2d..80925e4b793 100644
--- a/crates/agent_ui/src/conversation_view/thread_search_bar.rs
+++ b/crates/agent_ui/src/conversation_view/thread_search_bar.rs
@@ -744,7 +744,7 @@ impl Render for ThreadSearchBar {
.border_color(theme.border)
.bg(theme.editor_background)
.rounded_md()
- .child(div().flex_1().child(render_query_input(
+ .child(div().px_1().flex_1().child(render_query_input(
&self.query_editor,
in_error_state,
cx,
@@ -814,7 +814,7 @@ impl Render for ThreadSearchBar {
v_flex()
.w_full()
- .p_2()
+ .p_1p5()
.bg(theme.panel_background)
.border_b_1()
.border_color(theme.border.opacity(0.6))
diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rs
index 91aa12b63a0..118ceeb325f 100644
--- a/crates/agent_ui/src/conversation_view/thread_view.rs
+++ b/crates/agent_ui/src/conversation_view/thread_view.rs
@@ -1079,7 +1079,11 @@ impl ThreadView {
match event {
MessageEditorEvent::Send => self.send(window, cx),
MessageEditorEvent::SendImmediately => self.interrupt_and_send(window, cx),
- MessageEditorEvent::Cancel => self.cancel_generation(cx),
+ MessageEditorEvent::Cancel => {
+ if !self.close_thread_search(window, cx) {
+ self.cancel_generation(cx);
+ }
+ }
MessageEditorEvent::Focus => {
self.cancel_editing(&Default::default(), window, cx);
}
@@ -6321,6 +6325,27 @@ impl ThreadView {
}
}
+ /// Hides the thread search bar, clears its highlights, and returns focus to
+ /// the message editor. Returns `true` if the search bar was visible.
+ pub(crate) fn close_thread_search(
+ &mut self,
+ window: &mut Window,
+ cx: &mut Context<Self>,
+ ) -> bool {
+ if !self.thread_search_visible {
+ return false;
+ }
+
+ if let Some(bar) = self.thread_search_bar.clone() {
+ bar.update(cx, |bar, cx| bar.clear_highlights(cx));
+ }
+
+ self.thread_search_visible = false;
+ self.message_editor.focus_handle(cx).focus(window, cx);
+ cx.notify();
+ true
+ }
+
pub(crate) fn toggle_search(
&mut self,
_: &crate::ToggleSearch,
@@ -10993,27 +11018,15 @@ impl Render for ThreadView {
}))
.on_action(cx.listener(
|this, _: &super::thread_search_bar::DismissThreadSearch, window, cx| {
- if let Some(bar) = this.thread_search_bar.clone() {
- bar.update(cx, |bar, cx| bar.clear_highlights(cx));
- }
- this.thread_search_visible = false;
- this.message_editor.focus_handle(cx).focus(window, cx);
- cx.notify();
+ this.close_thread_search(window, cx);
},
))
// Esc can arrive as `editor::Cancel` from the query editor.
.on_action(
cx.listener(|this, _: &editor::actions::Cancel, window, cx| {
- if !this.thread_search_visible {
+ if !this.close_thread_search(window, cx) {
cx.propagate();
- return;
}
- if let Some(bar) = this.thread_search_bar.clone() {
- bar.update(cx, |bar, cx| bar.clear_highlights(cx));
- }
- this.thread_search_visible = false;
- this.message_editor.focus_handle(cx).focus(window, cx);
- cx.notify();
}),
)
.on_action(cx.listener(