Track tab opener relationships

This commit is contained in:
2026-05-08 05:07:19 -04:00
parent 1d90b5bc37
commit 06c37f89b0
3 changed files with 48 additions and 0 deletions
@@ -322,6 +322,7 @@ impl BrowserCore {
fn build_tab(&self, url: UrlText) -> BrowserTab {
self.build_tab_for(self.active_space_id.clone(), self.active_profile_id.clone(), url)
.with_parent_tab_id(self.active_tab_id.clone())
}
pub(super) fn nearest_tab_in_space(
+34
View File
@@ -22,6 +22,40 @@ fn opens_new_tab_below_active_tab() -> Result<(), Box<dyn Error>> {
Ok(())
}
#[test]
fn opened_tabs_record_active_tab_as_parent() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let first_tab_id = core.active_tab()?.id().clone();
let second_tab_id = core.open_tab(UrlText::parse("https://example.com")?);
let snapshot = core.snapshot()?;
let opened_tab = snapshot
.tabs
.iter()
.find(|tab| tab.id() == &second_tab_id)
.ok_or(CoreError::MissingActiveTab)?;
assert_eq!(opened_tab.parent_tab_id(), Some(&first_tab_id));
Ok(())
}
#[test]
fn replacement_tabs_have_no_parent_tab() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let active_tab_id = core.active_tab()?.id().clone();
let replacement_tab_id = core.close_tab(&active_tab_id)?;
let snapshot = core.snapshot()?;
let replacement_tab = snapshot
.tabs
.iter()
.find(|tab| tab.id() == &replacement_tab_id)
.ok_or(CoreError::MissingActiveTab)?;
assert_eq!(replacement_tab.parent_tab_id(), None);
Ok(())
}
#[test]
fn closes_active_tab_and_selects_next_neighbor() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
+13
View File
@@ -26,6 +26,7 @@ pub struct BrowserTab {
profile_id: ProfileId,
title: String,
url: UrlText,
parent_tab_id: Option<TabId>,
state: TabState,
flags: TabFlags,
split_id: Option<SplitId>,
@@ -49,6 +50,7 @@ impl BrowserTab {
profile_id,
title: title.into(),
url,
parent_tab_id: None,
state: TabState::Ready,
flags: TabFlags::default(),
split_id: None,
@@ -57,6 +59,12 @@ impl BrowserTab {
}
}
#[must_use]
pub fn with_parent_tab_id(mut self, parent_tab_id: TabId) -> Self {
self.parent_tab_id = Some(parent_tab_id);
self
}
#[must_use]
pub fn id(&self) -> &TabId {
&self.id
@@ -82,6 +90,11 @@ impl BrowserTab {
&self.url
}
#[must_use]
pub fn parent_tab_id(&self) -> Option<&TabId> {
self.parent_tab_id.as_ref()
}
#[must_use]
pub fn display_url(&self) -> String {
self.url.display_url()