Record browsing history in core

This commit is contained in:
2026-05-07 21:09:00 -04:00
parent 3bcf4460ca
commit d26ebdfb4c
8 changed files with 226 additions and 2 deletions
@@ -32,6 +32,10 @@ pub(crate) fn tab_matches_query(tab: &BrowserTab, normalized_query: &str) -> boo
|| tab.display_url().to_lowercase().contains(normalized_query)
}
pub(crate) fn records_history(url: &UrlText) -> bool {
Url::parse(url.as_str()).map(|parsed_url| parsed_url.scheme() != "ely").unwrap_or(false)
}
pub(crate) fn new_space_name(command: &str) -> Option<&str> {
command_argument(command, &["new-space ", "new space "])
}
+7 -2
View File
@@ -1,13 +1,14 @@
use std::collections::BTreeMap;
use ely_domain::{
ArchivedTab, BrowserTab, DomainError, Profile, ProfileId, ProfileKind, Space, SpaceId, TabId,
UrlText,
ArchivedTab, BrowserTab, DomainError, HistoryEntry, Profile, ProfileId, ProfileKind, Space,
SpaceId, TabId, UrlText,
};
use crate::CoreError;
mod commands;
mod history;
mod profiles;
mod tabs;
@@ -36,6 +37,7 @@ pub struct BrowserSnapshot {
pub favorites: Vec<BrowserTab>,
pub pinned_tabs: Vec<BrowserTab>,
pub archived_tabs: Vec<ArchivedTab>,
pub history_entries: Vec<HistoryEntry>,
pub spaces: Vec<Space>,
pub active_tab_id: TabId,
pub active_space_id: SpaceId,
@@ -50,6 +52,7 @@ pub struct BrowserCore {
profiles: Vec<Profile>,
tabs: Vec<BrowserTab>,
archived_tabs: Vec<ArchivedTab>,
history_entries: Vec<HistoryEntry>,
active_space_id: SpaceId,
active_profile_id: ProfileId,
active_tab_id: TabId,
@@ -90,6 +93,7 @@ impl BrowserCore {
profiles: vec![profile],
tabs: vec![tab],
archived_tabs: Vec::new(),
history_entries: Vec::new(),
command_query: String::new(),
new_tab_url,
})
@@ -175,6 +179,7 @@ impl BrowserCore {
favorites: self.favorites(),
pinned_tabs: self.pinned_tabs(),
archived_tabs: self.archived_tabs.clone(),
history_entries: self.visible_history(),
spaces: self.spaces.clone(),
tabs: self.visible_tabs(),
active_tab_id: self.active_tab_id.clone(),
@@ -44,6 +44,12 @@ impl BrowserCore {
self.command_query.clear();
}
}
CommandIntent::ScopedSearch { scope: CommandScope::History, query } => {
if let Some(url) = self.find_history_match(query) {
self.open_tab(url);
self.command_query.clear();
}
}
CommandIntent::ScopedSearch { scope: CommandScope::Settings, query } => {
if let Some(url) = settings_page_url(query)? {
self.open_tab(url);
@@ -0,0 +1,55 @@
use std::time::SystemTime;
use ely_domain::{BrowserTab, HistoryEntry, UrlText};
use crate::navigation::records_history;
use super::BrowserCore;
impl BrowserCore {
pub(super) fn record_history_entry(&mut self, tab: &BrowserTab) {
if !records_history(tab.url()) {
return;
}
self.history_entries.push(HistoryEntry::new(
tab.profile_id().clone(),
tab.space_id().clone(),
tab.title(),
tab.url().clone(),
SystemTime::now(),
));
}
pub(super) fn find_history_match(&self, query: &str) -> Option<UrlText> {
let normalized_query = query.trim().to_lowercase();
if normalized_query.is_empty() {
return None;
}
self.history_entries
.iter()
.rev()
.find(|entry| {
entry.profile_id() == &self.active_profile_id
&& entry.space_id() == &self.active_space_id
&& history_entry_matches_query(entry, &normalized_query)
})
.map(|entry| entry.url().clone())
}
pub(super) fn visible_history(&self) -> Vec<HistoryEntry> {
self.history_entries
.iter()
.filter(|entry| entry.profile_id() == &self.active_profile_id)
.filter(|entry| entry.space_id() == &self.active_space_id)
.cloned()
.collect()
}
}
fn history_entry_matches_query(entry: &HistoryEntry, normalized_query: &str) -> bool {
entry.title().to_lowercase().contains(normalized_query)
|| entry.url().as_str().to_lowercase().contains(normalized_query)
|| entry.url().display_url().to_lowercase().contains(normalized_query)
}
@@ -18,6 +18,7 @@ impl BrowserCore {
.iter()
.position(|existing| existing.id() == &self.active_tab_id)
.map_or(self.tabs.len(), |index| index + 1);
self.record_history_entry(&tab);
self.tabs.insert(insert_index, tab);
self.active_tab_id = tab_id.clone();
self.active_tabs_by_space.insert(self.active_space_id.clone(), tab_id.clone());