diff --git a/assets/keymaps/default.json b/assets/keymaps/default.json index 9c129cb1ac7373f1b8c17847767b7f2b8eeb9251..fa75d0ce1ba88b3144385d63bf7d8890239a5f90 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.rs index 863eb72fb319119e524b75ed25431aca1ceb44fc..9df62261a0f21fb25609a5b0ca15791771f9684e 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) { + fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext) { + 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) -> AnyElement { if let Some(_search) = self.active_project_search.as_ref() { let search = _search.read(cx);