Search archived tabs by context
This commit is contained in:
@@ -160,7 +160,7 @@ impl BrowserCore {
|
|||||||
let Some(index) = self
|
let Some(index) = self
|
||||||
.archived_tabs
|
.archived_tabs
|
||||||
.iter()
|
.iter()
|
||||||
.rposition(|archived| tab_matches_query(archived.tab(), &normalized_query))
|
.rposition(|archived| self.archived_tab_matches_query(archived, &normalized_query))
|
||||||
else {
|
else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
@@ -324,4 +324,28 @@ impl BrowserCore {
|
|||||||
.find(|tab| tab.space_id() == space_id && tab.profile_id() == profile_id)
|
.find(|tab| tab.space_id() == space_id && tab.profile_id() == profile_id)
|
||||||
.map(|tab| tab.id().clone())
|
.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)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<dyn Error>> {
|
||||||
|
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<dyn Error>> {
|
||||||
|
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(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user