Switch spaces from command scope

This commit is contained in:
2026-05-07 20:25:11 -04:00
parent 19d928859c
commit dcc4883797
3 changed files with 62 additions and 1 deletions
+11
View File
@@ -338,6 +338,17 @@ impl BrowserCore {
self.command_query.clear();
}
}
CommandIntent::ScopedSearch { scope: CommandScope::Spaces, query } => {
let query = query.trim().to_lowercase();
if let Some(space_id) = self.spaces.iter().find_map(|space| {
(space.name().to_lowercase().contains(&query)
|| space.icon().to_lowercase().contains(&query))
.then(|| space.id().clone())
}) {
self.select_space(&space_id)?;
self.command_query.clear();
}
}
CommandIntent::ScopedSearch { scope: CommandScope::Archive, query }
if self.restore_archived_tab_match(query)?.is_some() =>
{
+49 -1
View File
@@ -1,7 +1,7 @@
use std::error::Error;
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
use ely_domain::{CommandIntent, UrlText};
use ely_domain::{CommandIntent, CommandScope, UrlText};
#[test]
fn favorite_command_toggles_active_tab() -> Result<(), Box<dyn Error>> {
@@ -68,6 +68,54 @@ fn new_space_command_creates_and_selects_named_space() -> Result<(), Box<dyn Err
Ok(())
}
#[test]
fn spaces_scoped_search_selects_matching_space() -> 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)?;
core.open_tab(UrlText::parse("https://servo.org")?);
core.select_space(&work_space_id)?;
core.set_command_query("@spaces Research");
let intent = core.submit_command()?;
let snapshot = core.snapshot()?;
let active_tab = core.active_tab()?;
assert_eq!(
intent,
Some(CommandIntent::ScopedSearch {
scope: CommandScope::Spaces,
query: "Research".to_string()
})
);
assert_eq!(snapshot.active_space_id, research_space_id);
assert_eq!(snapshot.active_space_name, "Research");
assert_eq!(active_tab.url().as_str(), "https://servo.org");
assert_eq!(snapshot.command_query, "");
Ok(())
}
#[test]
fn spaces_scoped_search_preserves_query_without_match() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let active_space_id = core.snapshot()?.active_space_id;
core.set_command_query("@spaces absent");
let intent = core.submit_command()?;
let snapshot = core.snapshot()?;
assert_eq!(
intent,
Some(CommandIntent::ScopedSearch {
scope: CommandScope::Spaces,
query: "absent".to_string()
})
);
assert_eq!(snapshot.active_space_id, active_space_id);
assert_eq!(snapshot.command_query, "@spaces absent");
Ok(())
}
#[test]
fn close_tab_command_closes_active_tab() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
+2
View File
@@ -3,6 +3,7 @@ use crate::{DomainError, UrlText};
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum CommandScope {
Archive,
Spaces,
Tabs,
Bookmarks,
History,
@@ -45,6 +46,7 @@ fn parse_scope(value: &str) -> Option<(CommandScope, &str)> {
let (scope, query) = value.split_once(' ')?;
let scope = match scope {
"@archive" => CommandScope::Archive,
"@spaces" => CommandScope::Spaces,
"@tabs" => CommandScope::Tabs,
"@bookmarks" => CommandScope::Bookmarks,
"@history" => CommandScope::History,