From dcc488379783a8f2915b8caa1587814d516d1c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Thu, 7 May 2026 20:25:11 -0400 Subject: [PATCH] Switch spaces from command scope --- crates/ely_browser_core/src/state.rs | 11 +++++ crates/ely_browser_core/tests/commands.rs | 50 ++++++++++++++++++++++- crates/ely_domain/src/command.rs | 2 + 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/crates/ely_browser_core/src/state.rs b/crates/ely_browser_core/src/state.rs index d6ccac0..c2d5a3c 100644 --- a/crates/ely_browser_core/src/state.rs +++ b/crates/ely_browser_core/src/state.rs @@ -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() => { diff --git a/crates/ely_browser_core/tests/commands.rs b/crates/ely_browser_core/tests/commands.rs index c992a59..afa4907 100644 --- a/crates/ely_browser_core/tests/commands.rs +++ b/crates/ely_browser_core/tests/commands.rs @@ -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> { @@ -68,6 +68,54 @@ fn new_space_command_creates_and_selects_named_space() -> Result<(), Box 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)?; + 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> { + 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> { let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?; diff --git a/crates/ely_domain/src/command.rs b/crates/ely_domain/src/command.rs index 9b2ddbd..ccf9929 100644 --- a/crates/ely_domain/src/command.rs +++ b/crates/ely_domain/src/command.rs @@ -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,