From 5215c924ca8992b751419b995d1cf9341017606c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Fri, 8 May 2026 04:57:09 -0400 Subject: [PATCH] Track history source tabs --- crates/ely_browser_core/src/state/history.rs | 3 ++- crates/ely_browser_core/tests/history.rs | 6 +++-- crates/ely_domain/src/history.rs | 27 +++++++++++++++++--- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/crates/ely_browser_core/src/state/history.rs b/crates/ely_browser_core/src/state/history.rs index d58f8fe..7664a29 100644 --- a/crates/ely_browser_core/src/state/history.rs +++ b/crates/ely_browser_core/src/state/history.rs @@ -44,13 +44,14 @@ impl BrowserCore { && entry.space_id() == tab.space_id() && entry.url() == tab.url() }) { - entry.record_visit(tab.title(), visited_at); + entry.record_visit(tab.id().clone(), tab.title(), visited_at); return; } self.history_entries.push(HistoryEntry::new( tab.profile_id().clone(), tab.space_id().clone(), + tab.id().clone(), tab.title(), tab.url().clone(), visited_at, diff --git a/crates/ely_browser_core/tests/history.rs b/crates/ely_browser_core/tests/history.rs index 7ad9277..6227bb0 100644 --- a/crates/ely_browser_core/tests/history.rs +++ b/crates/ely_browser_core/tests/history.rs @@ -12,12 +12,13 @@ fn navigation_records_profile_and_space_history() -> Result<(), Box> let active_profile_id = core.active_tab()?.profile_id().clone(); let active_space_id = core.snapshot()?.active_space_id; - core.open_tab(UrlText::parse("https://example.com/research")?); + let source_tab_id = core.open_tab(UrlText::parse("https://example.com/research")?); let snapshot = core.snapshot()?; assert_eq!(snapshot.history_entries.len(), 1); assert_eq!(snapshot.history_entries[0].profile_id(), &active_profile_id); assert_eq!(snapshot.history_entries[0].space_id(), &active_space_id); + assert_eq!(snapshot.history_entries[0].source_tab_id(), &source_tab_id); assert_eq!(snapshot.history_entries[0].title(), "example.com"); assert_eq!(snapshot.history_entries[0].url().as_str(), "https://example.com/research"); assert_eq!(snapshot.history_entries[0].visit_count(), 1); @@ -28,12 +29,13 @@ fn navigation_records_profile_and_space_history() -> Result<(), Box> fn repeated_history_visits_increment_count_in_active_context() -> Result<(), Box> { let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?; core.open_tab(UrlText::parse("https://example.com/research")?); - core.open_tab(UrlText::parse("https://example.com/research")?); + let latest_source_tab_id = core.open_tab(UrlText::parse("https://example.com/research")?); let snapshot = core.snapshot()?; assert_eq!(snapshot.history_entries.len(), 1); assert_eq!(snapshot.history_entries[0].url().as_str(), "https://example.com/research"); + assert_eq!(snapshot.history_entries[0].source_tab_id(), &latest_source_tab_id); assert_eq!(snapshot.history_entries[0].visit_count(), 2); Ok(()) } diff --git a/crates/ely_domain/src/history.rs b/crates/ely_domain/src/history.rs index ed1fc71..bf51a95 100644 --- a/crates/ely_domain/src/history.rs +++ b/crates/ely_domain/src/history.rs @@ -1,11 +1,12 @@ use std::time::SystemTime; -use crate::{ProfileId, SpaceId, UrlText}; +use crate::{ProfileId, SpaceId, TabId, UrlText}; #[derive(Clone, Debug, Eq, PartialEq)] pub struct HistoryEntry { profile_id: ProfileId, space_id: SpaceId, + source_tab_id: TabId, title: String, url: UrlText, visited_at: SystemTime, @@ -17,14 +18,29 @@ impl HistoryEntry { pub fn new( profile_id: ProfileId, space_id: SpaceId, + source_tab_id: TabId, title: impl Into, url: UrlText, visited_at: SystemTime, ) -> Self { - Self { profile_id, space_id, title: title.into(), url, visited_at, visit_count: 1 } + Self { + profile_id, + space_id, + source_tab_id, + title: title.into(), + url, + visited_at, + visit_count: 1, + } } - pub fn record_visit(&mut self, title: impl Into, visited_at: SystemTime) { + pub fn record_visit( + &mut self, + source_tab_id: TabId, + title: impl Into, + visited_at: SystemTime, + ) { + self.source_tab_id = source_tab_id; self.title = title.into(); self.visited_at = visited_at; self.visit_count = self.visit_count.saturating_add(1); @@ -40,6 +56,11 @@ impl HistoryEntry { &self.space_id } + #[must_use] + pub fn source_tab_id(&self) -> &TabId { + &self.source_tab_id + } + #[must_use] pub fn title(&self) -> &str { &self.title