From 15cf65be62af41469058f4804e8a823dd140fc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Fri, 8 May 2026 02:16:14 -0400 Subject: [PATCH] Search archived tabs by context --- crates/ely_browser_core/src/state/tabs.rs | 26 ++++++++- .../ely_browser_core/tests/archive_search.rs | 58 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 crates/ely_browser_core/tests/archive_search.rs diff --git a/crates/ely_browser_core/src/state/tabs.rs b/crates/ely_browser_core/src/state/tabs.rs index 2cad9b9..f29d9da 100644 --- a/crates/ely_browser_core/src/state/tabs.rs +++ b/crates/ely_browser_core/src/state/tabs.rs @@ -160,7 +160,7 @@ impl BrowserCore { let Some(index) = self .archived_tabs .iter() - .rposition(|archived| tab_matches_query(archived.tab(), &normalized_query)) + .rposition(|archived| self.archived_tab_matches_query(archived, &normalized_query)) else { return Ok(None); }; @@ -324,4 +324,28 @@ impl BrowserCore { .find(|tab| tab.space_id() == space_id && tab.profile_id() == profile_id) .map(|tab| tab.id().clone()) } + + fn archived_tab_matches_query(&self, archived: &ArchivedTab, normalized_query: &str) -> bool { + let tab = archived.tab(); + tab_matches_query(tab, normalized_query) + || self.archived_tab_space_matches_query(tab, normalized_query) + || self.archived_tab_profile_matches_query(tab, normalized_query) + } + + fn archived_tab_space_matches_query(&self, tab: &BrowserTab, normalized_query: &str) -> bool { + self.spaces.iter().find(|space| space.id() == tab.space_id()).is_some_and(|space| { + space.name().to_lowercase().contains(normalized_query) + || space.icon().to_lowercase().contains(normalized_query) + || space.id().as_str().to_lowercase().contains(normalized_query) + }) + } + + fn archived_tab_profile_matches_query(&self, tab: &BrowserTab, normalized_query: &str) -> bool { + self.profiles.iter().find(|profile| profile.id() == tab.profile_id()).is_some_and( + |profile| { + profile.name().to_lowercase().contains(normalized_query) + || profile.id().as_str().to_lowercase().contains(normalized_query) + }, + ) + } } diff --git a/crates/ely_browser_core/tests/archive_search.rs b/crates/ely_browser_core/tests/archive_search.rs new file mode 100644 index 0000000..971dce9 --- /dev/null +++ b/crates/ely_browser_core/tests/archive_search.rs @@ -0,0 +1,58 @@ +use std::error::Error; + +use ely_browser_core::{BrowserCore, InitialBrowserConfig}; +use ely_domain::{CommandIntent, CommandScope, ProfileKind, UrlText}; + +#[test] +fn archive_scoped_search_restores_tab_by_space_name() -> Result<(), Box> { + let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?; + let work_space_id = core.snapshot()?.active_space_id; + let research_space_id = core.create_space("Research", "R", 0xf54e00)?; + let archived_tab_id = core.open_tab(UrlText::parse("https://example.com/context")?); + core.close_active_tab()?; + core.select_space(&work_space_id)?; + + core.set_command_query("@archive Research"); + let intent = core.submit_command()?; + let snapshot = core.snapshot()?; + + assert_eq!( + intent, + Some(CommandIntent::ScopedSearch { + scope: CommandScope::Archive, + query: "Research".to_string(), + }) + ); + assert_eq!(snapshot.active_tab_id, archived_tab_id); + assert_eq!(snapshot.active_space_id, research_space_id); + assert!(snapshot.archived_tabs.is_empty()); + assert_eq!(snapshot.command_query, ""); + Ok(()) +} + +#[test] +fn archive_scoped_search_restores_tab_by_profile_name() -> Result<(), Box> { + let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?; + let default_profile_id = core.snapshot()?.active_profile_id; + let client_profile_id = core.create_profile("Client", 0xf54e00, ProfileKind::Standard)?; + let archived_tab_id = core.open_tab(UrlText::parse("https://example.com/account")?); + core.close_active_tab()?; + core.select_profile(&default_profile_id)?; + + core.set_command_query("@archive Client"); + let intent = core.submit_command()?; + let snapshot = core.snapshot()?; + + assert_eq!( + intent, + Some(CommandIntent::ScopedSearch { + scope: CommandScope::Archive, + query: "Client".to_string(), + }) + ); + assert_eq!(snapshot.active_tab_id, archived_tab_id); + assert_eq!(snapshot.active_profile_id, client_profile_id); + assert!(snapshot.archived_tabs.is_empty()); + assert_eq!(snapshot.command_query, ""); + Ok(()) +}