Track tab opener relationships
This commit is contained in:
@@ -322,6 +322,7 @@ impl BrowserCore {
|
|||||||
|
|
||||||
fn build_tab(&self, url: UrlText) -> BrowserTab {
|
fn build_tab(&self, url: UrlText) -> BrowserTab {
|
||||||
self.build_tab_for(self.active_space_id.clone(), self.active_profile_id.clone(), url)
|
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(
|
pub(super) fn nearest_tab_in_space(
|
||||||
|
|||||||
@@ -22,6 +22,40 @@ fn opens_new_tab_below_active_tab() -> Result<(), Box<dyn Error>> {
|
|||||||
Ok(())
|
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]
|
#[test]
|
||||||
fn closes_active_tab_and_selects_next_neighbor() -> Result<(), Box<dyn Error>> {
|
fn closes_active_tab_and_selects_next_neighbor() -> Result<(), Box<dyn Error>> {
|
||||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ pub struct BrowserTab {
|
|||||||
profile_id: ProfileId,
|
profile_id: ProfileId,
|
||||||
title: String,
|
title: String,
|
||||||
url: UrlText,
|
url: UrlText,
|
||||||
|
parent_tab_id: Option<TabId>,
|
||||||
state: TabState,
|
state: TabState,
|
||||||
flags: TabFlags,
|
flags: TabFlags,
|
||||||
split_id: Option<SplitId>,
|
split_id: Option<SplitId>,
|
||||||
@@ -49,6 +50,7 @@ impl BrowserTab {
|
|||||||
profile_id,
|
profile_id,
|
||||||
title: title.into(),
|
title: title.into(),
|
||||||
url,
|
url,
|
||||||
|
parent_tab_id: None,
|
||||||
state: TabState::Ready,
|
state: TabState::Ready,
|
||||||
flags: TabFlags::default(),
|
flags: TabFlags::default(),
|
||||||
split_id: None,
|
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]
|
#[must_use]
|
||||||
pub fn id(&self) -> &TabId {
|
pub fn id(&self) -> &TabId {
|
||||||
&self.id
|
&self.id
|
||||||
@@ -82,6 +90,11 @@ impl BrowserTab {
|
|||||||
&self.url
|
&self.url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn parent_tab_id(&self) -> Option<&TabId> {
|
||||||
|
self.parent_tab_id.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn display_url(&self) -> String {
|
pub fn display_url(&self) -> String {
|
||||||
self.url.display_url()
|
self.url.display_url()
|
||||||
|
|||||||
Reference in New Issue
Block a user