fix(tabs): keep the remembered active tab when closing a background tab

This commit is contained in:
2026-07-10 12:09:30 -04:00
parent 7a7e911e38
commit bfab49106d
2 changed files with 39 additions and 4 deletions
+12 -2
View File
@@ -104,18 +104,28 @@ impl BrowserCore {
let closed_space_id = closed_tab.space_id().clone(); let closed_space_id = closed_tab.space_id().clone();
let closed_profile_id = closed_tab.profile_id().clone(); let closed_profile_id = closed_tab.profile_id().clone();
let was_space_active_tab = self.active_tabs_by_space.get(&closed_space_id) == Some(tab_id); let was_space_active_tab = self.active_tabs_by_space.get(&closed_space_id) == Some(tab_id);
let was_profile_active_tab = self
.active_tabs_by_space_profile
.get(&(closed_space_id.clone(), closed_profile_id.clone()))
== Some(tab_id);
closed_tab.clear_split_id(); closed_tab.clear_split_id();
self.detach_tab_from_split(tab_id); self.detach_tab_from_split(tab_id);
if was_profile_active_tab {
self.active_tabs_by_space_profile self.active_tabs_by_space_profile
.remove(&(closed_space_id.clone(), closed_profile_id.clone())); .remove(&(closed_space_id.clone(), closed_profile_id.clone()));
}
self.archived_tabs.push(ArchivedTab::new(closed_tab, ArchiveSource::ManualClose)); self.archived_tabs.push(ArchivedTab::new(closed_tab, ArchiveSource::ManualClose));
if let Some(next_tab_id) = self.nearest_tab_in_space(&closed_space_id, close_index) { if let Some(next_tab_id) = self.nearest_tab_in_space(&closed_space_id, close_index) {
if was_space_active_tab { if was_space_active_tab {
self.active_tabs_by_space.insert(closed_space_id.clone(), next_tab_id.clone()); self.active_tabs_by_space.insert(closed_space_id.clone(), next_tab_id.clone());
} }
if let Some(next_profile_tab_id) = if was_profile_active_tab
self.nearest_tab_in_space_profile(&closed_space_id, &closed_profile_id, close_index) && let Some(next_profile_tab_id) = self.nearest_tab_in_space_profile(
&closed_space_id,
&closed_profile_id,
close_index,
)
{ {
self.active_tabs_by_space_profile self.active_tabs_by_space_profile
.insert((closed_space_id, closed_profile_id), next_profile_tab_id); .insert((closed_space_id, closed_profile_id), next_profile_tab_id);
@@ -0,0 +1,25 @@
use std::error::Error;
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
use ely_domain::{ProfileKind, UrlText};
#[test]
fn closing_a_background_tab_keeps_the_remembered_active_tab() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let first_profile_id = core.active_tab()?.profile_id().clone();
let tab_a = core.open_tab(UrlText::parse("https://example.com/a")?);
let _tab_b = core.open_tab(UrlText::parse("https://example.com/b")?);
let tab_c = core.open_tab(UrlText::parse("https://example.com/c")?);
core.select_tab(&tab_a)?;
core.close_tab(&tab_c)?;
core.create_profile("Second", 0xf54e00, ProfileKind::Standard)?;
let restored = core.select_profile(&first_profile_id)?;
assert_eq!(
restored, tab_a,
"closing a background tab must not clobber the remembered active tab"
);
Ok(())
}