Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
project_replace: Fix up key bindings (#3034)
Piotr Osiewicz36f022bb587b
diff --git a/assets/keymaps/default.json b/assets/keymaps/default.jsonindex 9c129cb1ac7..fa75d0ce1ba 100644--- a/assets/keymaps/default.json+++ b/assets/keymaps/default.json@@ -262,6 +262,13 @@"down": "search::NextHistoryQuery"}},+ {+ "context": "ProjectSearchBar && in_replace",+ "bindings": {+ "enter": "search::ReplaceNext",+ "cmd-enter": "search::ReplaceAll"+ }+ },{"context": "ProjectSearchView","bindings": {@@ -563,7 +570,7 @@}},{- "context": "ProjectSearchBar",+ "context": "ProjectSearchBar && !in_replace","bindings": {"cmd-enter": "project_search::SearchInNew"}diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rsindex 863eb72fb31..9df62261a0f 100644--- a/crates/search/src/project_search.rs+++ b/crates/search/src/project_search.rs@@ -60,7 +60,7 @@ pub fn init(cx: &mut AppContext) {cx.set_global(ActiveSettings::default());cx.add_action(ProjectSearchView::deploy);cx.add_action(ProjectSearchView::move_focus_to_results);- cx.add_action(ProjectSearchBar::search);+ cx.add_action(ProjectSearchBar::confirm);cx.add_action(ProjectSearchBar::search_in_new);cx.add_action(ProjectSearchBar::select_next_match);cx.add_action(ProjectSearchBar::select_prev_match);@@ -1371,9 +1371,18 @@ impl ProjectSearchBar {})}}- fn search(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {+ fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {+ let mut should_propagate = true;if let Some(search_view) = self.active_project_search.as_ref() {- search_view.update(cx, |search_view, cx| search_view.search(cx));+ search_view.update(cx, |search_view, cx| {+ if !search_view.replacement_editor.is_focused(cx) {+ should_propagate = false;+ search_view.search(cx);+ }+ });+ }+ if should_propagate {+ cx.propagate_action();}}@@ -1678,6 +1687,28 @@ impl View for ProjectSearchBar {"ProjectSearchBar"}+ fn update_keymap_context(+ &self,+ keymap: &mut gpui::keymap_matcher::KeymapContext,+ cx: &AppContext,+ ) {+ Self::reset_to_default_keymap_context(keymap);+ let in_replace = self+ .active_project_search+ .as_ref()+ .map(|search| {+ search+ .read(cx)+ .replacement_editor+ .read_with(cx, |_, cx| cx.is_self_focused())+ })+ .flatten()+ .unwrap_or(false);+ if in_replace {+ keymap.add_identifier("in_replace");+ }+ }+fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {if let Some(_search) = self.active_project_search.as_ref() {let search = _search.read(cx);