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
@@ -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());