Switch spaces from command scope
This commit is contained in:
@@ -338,6 +338,17 @@ impl BrowserCore {
|
|||||||
self.command_query.clear();
|
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 }
|
CommandIntent::ScopedSearch { scope: CommandScope::Archive, query }
|
||||||
if self.restore_archived_tab_match(query)?.is_some() =>
|
if self.restore_archived_tab_match(query)?.is_some() =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
|
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
|
||||||
use ely_domain::{CommandIntent, UrlText};
|
use ely_domain::{CommandIntent, CommandScope, UrlText};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn favorite_command_toggles_active_tab() -> Result<(), Box<dyn Error>> {
|
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(())
|
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]
|
#[test]
|
||||||
fn close_tab_command_closes_active_tab() -> Result<(), Box<dyn Error>> {
|
fn close_tab_command_closes_active_tab() -> Result<(), Box<dyn Error>> {
|
||||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use crate::{DomainError, UrlText};
|
|||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum CommandScope {
|
pub enum CommandScope {
|
||||||
Archive,
|
Archive,
|
||||||
|
Spaces,
|
||||||
Tabs,
|
Tabs,
|
||||||
Bookmarks,
|
Bookmarks,
|
||||||
History,
|
History,
|
||||||
@@ -45,6 +46,7 @@ fn parse_scope(value: &str) -> Option<(CommandScope, &str)> {
|
|||||||
let (scope, query) = value.split_once(' ')?;
|
let (scope, query) = value.split_once(' ')?;
|
||||||
let scope = match scope {
|
let scope = match scope {
|
||||||
"@archive" => CommandScope::Archive,
|
"@archive" => CommandScope::Archive,
|
||||||
|
"@spaces" => CommandScope::Spaces,
|
||||||
"@tabs" => CommandScope::Tabs,
|
"@tabs" => CommandScope::Tabs,
|
||||||
"@bookmarks" => CommandScope::Bookmarks,
|
"@bookmarks" => CommandScope::Bookmarks,
|
||||||
"@history" => CommandScope::History,
|
"@history" => CommandScope::History,
|
||||||
|
|||||||
Reference in New Issue
Block a user