diff --git a/Cargo.lock b/Cargo.lock index bd0a86d16128c219047e2ea3b47548534192d1a2..cddd744a9f8ffa5b6a7f02dfe49066a0ba0e6e58 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7057,6 +7057,7 @@ dependencies = [ "pretty_assertions", "project2", "schemars", + "search2", "serde", "serde_derive", "serde_json", diff --git a/crates/project_panel2/Cargo.toml b/crates/project_panel2/Cargo.toml index 48abfbe1def3493c46e0ddbb21ad077232a41a70..d3ef1eb825ccb45aa2818eb862f1584d6230de56 100644 --- a/crates/project_panel2/Cargo.toml +++ b/crates/project_panel2/Cargo.toml @@ -15,6 +15,7 @@ editor = { path = "../editor2", package = "editor2" } gpui = { path = "../gpui2", package = "gpui2" } menu = { path = "../menu2", package = "menu2" } project = { path = "../project2", package = "project2" } +search = { package = "search2", path = "../search2" } settings = { path = "../settings2", package = "settings2" } theme = { path = "../theme2", package = "theme2" } ui = { path = "../ui2", package = "ui2" } diff --git a/crates/project_panel2/src/project_panel.rs b/crates/project_panel2/src/project_panel.rs index d8b5c1551f4ef33495e7d84b168a702182479017..07a6e4be5ef0d8d545a4c971beeaf3183a6ad4b7 100644 --- a/crates/project_panel2/src/project_panel.rs +++ b/crates/project_panel2/src/project_panel.rs @@ -55,7 +55,7 @@ pub struct ProjectPanel { filename_editor: View, clipboard_entry: Option, _dragged_entry_destination: Option>, - _workspace: WeakView, + workspace: WeakView, width: Option, pending_serialization: Task>, } @@ -152,10 +152,6 @@ pub enum Event { entry_id: ProjectEntryId, }, Focus, - NewSearchInDirectory { - dir_entry: Entry, - }, - ActivatePanel, } #[derive(Serialize, Deserialize)] @@ -190,10 +186,10 @@ impl ProjectPanel { } project::Event::RevealInProjectPanel(entry_id) => { this.reveal_entry(project, *entry_id, false, cx); - cx.emit(Event::ActivatePanel); + cx.emit(PanelEvent::Activate); } project::Event::ActivateProjectPanel => { - cx.emit(Event::ActivatePanel); + cx.emit(PanelEvent::Activate); } project::Event::WorktreeRemoved(id) => { this.expanded_dir_ids.remove(id); @@ -244,7 +240,7 @@ impl ProjectPanel { filename_editor, clipboard_entry: None, _dragged_entry_destination: None, - _workspace: workspace.weak_handle(), + workspace: workspace.weak_handle(), width: None, pending_serialization: Task::ready(None), }; @@ -1004,9 +1000,12 @@ impl ProjectPanel { ) { if let Some((_, entry)) = self.selected_entry(cx) { if entry.is_dir() { - cx.emit(Event::NewSearchInDirectory { - dir_entry: entry.clone(), - }); + let entry = entry.clone(); + self.workspace + .update(cx, |workspace, cx| { + search::ProjectSearchView::new_search_in_directory(workspace, &entry, cx); + }) + .ok(); } } } @@ -1666,7 +1665,6 @@ mod tests { use std::{ collections::HashSet, path::{Path, PathBuf}, - sync::atomic::{self, AtomicUsize}, }; use workspace::AppState; @@ -2705,87 +2703,6 @@ mod tests { ); } - #[gpui::test] - async fn test_new_search_in_directory_trigger(cx: &mut gpui::TestAppContext) { - init_test_with_editor(cx); - - let fs = FakeFs::new(cx.executor().clone()); - fs.insert_tree( - "/src", - json!({ - "test": { - "first.rs": "// First Rust file", - "second.rs": "// Second Rust file", - "third.rs": "// Third Rust file", - } - }), - ) - .await; - - let project = Project::test(fs.clone(), ["/src".as_ref()], cx).await; - let workspace = cx.add_window(|cx| Workspace::test_new(project.clone(), cx)); - let cx = &mut VisualTestContext::from_window(*workspace, cx); - let panel = workspace - .update(cx, |workspace, cx| ProjectPanel::new(workspace, cx)) - .unwrap(); - - let new_search_events_count = Arc::new(AtomicUsize::new(0)); - let _subscription = panel.update(cx, |_, cx| { - let subcription_count = Arc::clone(&new_search_events_count); - let view = cx.view().clone(); - cx.subscribe(&view, move |_, _, event, _| { - if matches!(event, Event::NewSearchInDirectory { .. }) { - subcription_count.fetch_add(1, atomic::Ordering::SeqCst); - } - }) - }); - - toggle_expand_dir(&panel, "src/test", cx); - select_path(&panel, "src/test/first.rs", cx); - panel.update(cx, |panel, cx| panel.confirm(&Confirm, cx)); - cx.executor().run_until_parked(); - assert_eq!( - visible_entries_as_strings(&panel, 0..10, cx), - &[ - "v src", - " v test", - " first.rs <== selected", - " second.rs", - " third.rs" - ] - ); - panel.update(cx, |panel, cx| { - panel.new_search_in_directory(&NewSearchInDirectory, cx) - }); - assert_eq!( - new_search_events_count.load(atomic::Ordering::SeqCst), - 0, - "Should not trigger new search in directory when called on a file" - ); - - select_path(&panel, "src/test", cx); - panel.update(cx, |panel, cx| panel.confirm(&Confirm, cx)); - cx.executor().run_until_parked(); - assert_eq!( - visible_entries_as_strings(&panel, 0..10, cx), - &[ - "v src", - " v test <== selected", - " first.rs", - " second.rs", - " third.rs" - ] - ); - panel.update(cx, |panel, cx| { - panel.new_search_in_directory(&NewSearchInDirectory, cx) - }); - assert_eq!( - new_search_events_count.load(atomic::Ordering::SeqCst), - 1, - "Should trigger new search in directory when called on a directory" - ); - } - #[gpui::test] async fn test_collapse_all_entries(cx: &mut gpui::TestAppContext) { init_test_with_editor(cx); diff --git a/crates/search2/src/project_search.rs b/crates/search2/src/project_search.rs index af8ac418347a9b5f9e06888dd3bac3e8c4b8a143..3e245ed72d4a9e8523b281ef79ee58387b2ad5bd 100644 --- a/crates/search2/src/project_search.rs +++ b/crates/search2/src/project_search.rs @@ -918,6 +918,7 @@ impl ProjectSearchView { }) .unwrap_or(Task::ready(Ok(false))) } + pub fn new_search_in_directory( workspace: &mut Workspace, dir_entry: &Entry, diff --git a/crates/search2/src/search.rs b/crates/search2/src/search.rs index a5bd299e874603a9c2be6147f0c5e5a9d74ad8d9..f0301a5bcc7a637c17d47c59f5102f352ac3840c 100644 --- a/crates/search2/src/search.rs +++ b/crates/search2/src/search.rs @@ -3,6 +3,7 @@ pub use buffer_search::BufferSearchBar; use gpui::{actions, Action, AppContext, IntoElement}; pub use mode::SearchMode; use project::search::SearchQuery; +pub use project_search::ProjectSearchView; use ui::{prelude::*, Tooltip}; use ui::{ButtonStyle, IconButton};