Split browser command handling
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ely_domain::{
|
||||
ArchiveSource, ArchivedTab, BrowserTab, CommandIntent, CommandScope, DomainError, Profile,
|
||||
ProfileId, ProfileKind, Space, SpaceId, TabId, UrlText,
|
||||
ArchiveSource, ArchivedTab, BrowserTab, DomainError, Profile, ProfileId, ProfileKind, Space,
|
||||
SpaceId, TabId, UrlText,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
CoreError,
|
||||
navigation::{new_space_name, search_url, space_icon, tab_matches_query, tab_title},
|
||||
navigation::{tab_matches_query, tab_title},
|
||||
};
|
||||
|
||||
mod commands;
|
||||
|
||||
const DEFAULT_FAVORITE_LIMIT: usize = 12;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -311,55 +313,6 @@ impl BrowserCore {
|
||||
&self.command_query
|
||||
}
|
||||
|
||||
pub fn submit_command(&mut self) -> Result<Option<CommandIntent>, CoreError> {
|
||||
let query = self.command_query.trim();
|
||||
if query.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let intent = CommandIntent::parse(query)?;
|
||||
match &intent {
|
||||
CommandIntent::Navigate(url) => {
|
||||
self.open_tab(url.clone());
|
||||
self.command_query.clear();
|
||||
}
|
||||
CommandIntent::Search(query) => {
|
||||
let url = search_url(query)?;
|
||||
self.open_tab(url);
|
||||
self.command_query.clear();
|
||||
}
|
||||
CommandIntent::Command(command) if self.submit_named_command(command)? => {
|
||||
self.command_query.clear();
|
||||
}
|
||||
CommandIntent::Command(_) => {}
|
||||
CommandIntent::ScopedSearch { scope: CommandScope::Tabs, query } => {
|
||||
if let Some(tab_id) = self.find_tab_match(query) {
|
||||
self.select_tab(&tab_id)?;
|
||||
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() =>
|
||||
{
|
||||
self.command_query.clear();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Ok(Some(intent))
|
||||
}
|
||||
|
||||
pub fn snapshot(&self) -> Result<BrowserSnapshot, CoreError> {
|
||||
let active_space = self
|
||||
.spaces
|
||||
@@ -411,38 +364,6 @@ impl BrowserCore {
|
||||
Ok(next_tab_id)
|
||||
}
|
||||
|
||||
fn submit_named_command(&mut self, command: &str) -> Result<bool, CoreError> {
|
||||
let command = command.trim();
|
||||
if let Some(name) = new_space_name(command) {
|
||||
self.create_space(name.to_string(), space_icon(name), 0xf54e00)?;
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
match command.to_ascii_lowercase().as_str() {
|
||||
"new-tab" => {
|
||||
self.open_tab(self.new_tab_url.clone());
|
||||
Ok(true)
|
||||
}
|
||||
"close-tab" => {
|
||||
self.close_active_tab()?;
|
||||
Ok(true)
|
||||
}
|
||||
"favorite" | "toggle-favorite" => {
|
||||
self.toggle_active_tab_favorite()?;
|
||||
Ok(true)
|
||||
}
|
||||
"pin" | "pin-tab" | "toggle-pin" => {
|
||||
self.toggle_active_tab_pinned()?;
|
||||
Ok(true)
|
||||
}
|
||||
"restore-tab" | "reopen-tab" => {
|
||||
self.restore_last_archived_tab()?;
|
||||
Ok(true)
|
||||
}
|
||||
_ => Ok(false),
|
||||
}
|
||||
}
|
||||
|
||||
fn active_tab_index(&self) -> Result<usize, CoreError> {
|
||||
self.tabs
|
||||
.iter()
|
||||
|
||||
Reference in New Issue
Block a user