From 617a8d68deec0cd82a82eda670f37cfeed386ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Tue, 6 Oct 2026 04:51:15 -0400 Subject: [PATCH] =?UTF-8?q?Editor=20=C2=B7=20FindWidget:=20Escape=20from?= =?UTF-8?q?=20the=20query=20closes=20the=20box?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/editor/find.rs | 9 +++++++++ src/editor/tests.rs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/editor/find.rs b/src/editor/find.rs index 67754a7..f2a3564 100644 --- a/src/editor/find.rs +++ b/src/editor/find.rs @@ -206,6 +206,15 @@ impl RenderOnce for FindWidget { .bg(colors.overlay) .shadow(theme.elevation(Elevation::Floating)) .text_size(theme.text_size(TextSize::Xs)) + // Escape from the query closes the box. + .when_some(self.on_close.clone(), |el, close| { + el.on_key_down(move |event, window, cx| { + if event.keystroke.key == "escape" { + cx.stop_propagation(); + close(window, cx); + } + }) + }) .child( row() .children(self.on_toggle_replace.clone().map(|fold| { diff --git a/src/editor/tests.rs b/src/editor/tests.rs index c0d1d85..516f37c 100644 --- a/src/editor/tests.rs +++ b/src/editor/tests.rs @@ -283,3 +283,38 @@ fn only_a_focused_editor_blinks(cx: &mut TestAppContext) { cx.run_until_parked(); assert!(redraws.get() > 2, "a focused one blinks"); } + +#[gpui::test] +fn escape_in_the_find_query_closes_the_box(cx: &mut TestAppContext) { + use gpui::{ + AppContext as _, Focusable as _, IntoElement, ParentElement as _, Render, Styled as _, + Window, div, + }; + + use crate::forms::TextInput; + + struct Host { + query: Entity, + closed: Rc>, + } + impl Render for Host { + fn render(&mut self, _: &mut Window, _: &mut gpui::Context) -> impl IntoElement { + let closed = self.closed.clone(); + let find = super::FindWidget::new("find", &self.query, None, 0) + .on_close(move |_, _| closed.set(true)); + div().size_full().child(find) + } + } + cx.update(Theme::init); + let closed = Rc::new(Cell::new(false)); + let shut = closed.clone(); + let (host, cx) = cx.add_window_view(move |window, cx| Host { + query: cx.new(|cx| TextInput::new(window, cx)), + closed: shut, + }); + let field = host.read_with(cx, |host, cx| host.query.focus_handle(cx)); + cx.update(|window, cx| window.focus(&field, cx)); + cx.run_until_parked(); + cx.simulate_keystrokes("escape"); + assert!(closed.get(), "escape closes the find box"); +}