Open downloads from command bar
This commit is contained in:
@@ -6,13 +6,21 @@ use crate::CoreError;
|
||||
const DEFAULT_SEARCH_URL: &str = "https://duckduckgo.com/";
|
||||
|
||||
pub(crate) fn tab_title(url: &UrlText) -> String {
|
||||
if url.as_str() == "ely://new-tab" {
|
||||
return "New Tab".to_string();
|
||||
if let Some(title) = internal_page_title(url.as_str()) {
|
||||
return title.to_string();
|
||||
}
|
||||
|
||||
url.display_host()
|
||||
}
|
||||
|
||||
fn internal_page_title(url: &str) -> Option<&'static str> {
|
||||
match url {
|
||||
"ely://new-tab" => Some("New Tab"),
|
||||
"ely://downloads" => Some("Downloads"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn tab_matches_query(tab: &BrowserTab, normalized_query: &str) -> bool {
|
||||
tab.title().to_lowercase().contains(normalized_query)
|
||||
|| tab.url().as_str().to_lowercase().contains(normalized_query)
|
||||
@@ -59,3 +67,7 @@ pub(crate) fn search_url(query: &str) -> Result<UrlText, CoreError> {
|
||||
url.query_pairs_mut().append_pair("q", query);
|
||||
UrlText::parse(url.to_string()).map_err(CoreError::from)
|
||||
}
|
||||
|
||||
pub(crate) fn downloads_url() -> Result<UrlText, CoreError> {
|
||||
UrlText::parse("ely://downloads").map_err(CoreError::from)
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ use ely_domain::{CommandIntent, CommandScope, ProfileId, ProfileKind, SpaceId};
|
||||
use crate::{
|
||||
CoreError,
|
||||
navigation::{
|
||||
move_tab_space_name, new_profile_name, new_space_name, search_url, space_icon,
|
||||
switch_profile_name,
|
||||
downloads_url, move_tab_space_name, new_profile_name, new_space_name, search_url,
|
||||
space_icon, switch_profile_name,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -85,6 +85,10 @@ impl BrowserCore {
|
||||
self.open_tab(self.new_tab_url.clone());
|
||||
Ok(true)
|
||||
}
|
||||
"downloads" | "open-downloads" | "open downloads" => {
|
||||
self.open_tab(downloads_url()?);
|
||||
Ok(true)
|
||||
}
|
||||
"close-tab" => {
|
||||
self.close_active_tab()?;
|
||||
Ok(true)
|
||||
|
||||
@@ -49,6 +49,23 @@ fn new_tab_command_opens_new_tab() -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_downloads_command_opens_downloads_page() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
|
||||
core.set_command_query(">open-downloads");
|
||||
let intent = core.submit_command()?;
|
||||
let snapshot = core.snapshot()?;
|
||||
let active_tab = core.active_tab()?;
|
||||
|
||||
assert_eq!(intent, Some(CommandIntent::Command("open-downloads".to_string())));
|
||||
assert_eq!(snapshot.tabs.len(), 2);
|
||||
assert_eq!(active_tab.title(), "Downloads");
|
||||
assert_eq!(active_tab.url().as_str(), "ely://downloads");
|
||||
assert_eq!(snapshot.command_query, "");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_space_command_creates_and_selects_named_space() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
|
||||
Reference in New Issue
Block a user