Add tab group sleep command

This commit is contained in:
2026-05-08 10:40:24 -04:00
parent f167b7999b
commit a05b662fd6
4 changed files with 81 additions and 1 deletions
@@ -213,6 +213,9 @@ impl BrowserCore {
Ok(self.set_active_tab_group_collapsed(false)?.is_some()) Ok(self.set_active_tab_group_collapsed(false)?.is_some())
} }
"ungroup-tab" | "ungroup tab" => self.ungroup_active_tab(), "ungroup-tab" | "ungroup tab" => self.ungroup_active_tab(),
"sleep-tab-group" | "sleep tab group" | "discard-tab-group" | "discard tab group" => {
Ok(self.discard_active_tab_group()?.is_some())
}
"downloads" | "open-downloads" | "open downloads" => { "downloads" | "open-downloads" | "open downloads" => {
self.open_tab(downloads_url()?); self.open_tab(downloads_url()?);
Ok(true) Ok(true)
@@ -80,6 +80,19 @@ impl BrowserCore {
Ok(true) Ok(true)
} }
pub fn discard_active_tab_group(&mut self) -> Result<Option<usize>, CoreError> {
let Some(group_id) = self.active_tab_group_id()? else {
return Ok(None);
};
let tab_ids = self.active_space_group_tab_ids(&group_id);
for tab_id in &tab_ids {
self.discard_tab(tab_id)?;
}
Ok(Some(tab_ids.len()))
}
pub fn split_active_tab_group(&mut self) -> Result<Option<SplitId>, CoreError> { pub fn split_active_tab_group(&mut self) -> Result<Option<SplitId>, CoreError> {
let Some(group_id) = self.active_tab_group_id()? else { let Some(group_id) = self.active_tab_group_id()? else {
return Ok(None); return Ok(None);
@@ -269,6 +282,10 @@ impl BrowserCore {
) )
} }
fn active_space_group_tab_ids(&self, group_id: &TabGroupId) -> Vec<TabId> {
self.active_space_group_tabs(group_id).iter().map(|tab| tab.id().clone()).collect()
}
fn split_pane_space_id( fn split_pane_space_id(
&self, &self,
split_id: &SplitId, split_id: &SplitId,
+44 -1
View File
@@ -1,7 +1,7 @@
use std::error::Error; use std::error::Error;
use ely_browser_core::{BrowserCore, CoreError, InitialBrowserConfig}; use ely_browser_core::{BrowserCore, CoreError, InitialBrowserConfig};
use ely_domain::{CommandIntent, MAX_SPLIT_PANES, SplitAxis, UrlText}; use ely_domain::{CommandIntent, MAX_SPLIT_PANES, SplitAxis, TabState, UrlText};
#[test] #[test]
fn group_active_tab_creates_visible_space_group() -> Result<(), Box<dyn Error>> { fn group_active_tab_creates_visible_space_group() -> Result<(), Box<dyn Error>> {
@@ -167,6 +167,42 @@ fn auto_group_domains_preserves_existing_manual_groups() -> Result<(), Box<dyn E
Ok(()) Ok(())
} }
#[test]
fn sleep_tab_group_command_discards_active_group_tabs() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let ungrouped_tab_id = core.open_tab(UrlText::parse("https://servo.org")?);
let first_group_tab_id = core.open_tab(UrlText::parse("https://example.com/a")?);
core.group_active_tab("Docs")?;
let second_group_tab_id = core.open_tab(UrlText::parse("https://example.com/b")?);
core.group_active_tab("Docs")?;
core.set_command_query(">sleep-tab-group");
let intent = core.submit_command()?;
let snapshot = core.snapshot()?;
assert_eq!(intent, Some(CommandIntent::Command("sleep-tab-group".to_string())));
assert_eq!(snapshot.command_query, "");
assert_eq!(tab_state(&snapshot, &first_group_tab_id), Some(&TabState::Discarded));
assert_eq!(tab_state(&snapshot, &second_group_tab_id), Some(&TabState::Discarded));
assert_eq!(tab_state(&snapshot, &ungrouped_tab_id), Some(&TabState::Ready));
Ok(())
}
#[test]
fn sleep_tab_group_command_preserves_query_without_active_group() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let tab_id = core.open_tab(UrlText::parse("https://example.com")?);
core.set_command_query(">sleep-tab-group");
let intent = core.submit_command()?;
let snapshot = core.snapshot()?;
assert_eq!(intent, Some(CommandIntent::Command("sleep-tab-group".to_string())));
assert_eq!(snapshot.command_query, ">sleep-tab-group");
assert_eq!(tab_state(&snapshot, &tab_id), Some(&TabState::Ready));
Ok(())
}
#[test] #[test]
fn tab_group_collapse_commands_update_active_group() -> Result<(), Box<dyn Error>> { fn tab_group_collapse_commands_update_active_group() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?; let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
@@ -333,3 +369,10 @@ fn tab_group_id<'a>(
) -> Option<&'a ely_domain::TabGroupId> { ) -> Option<&'a ely_domain::TabGroupId> {
snapshot.tabs.iter().find(|tab| tab.id() == tab_id).and_then(|tab| tab.group_id()) snapshot.tabs.iter().find(|tab| tab.id() == tab_id).and_then(|tab| tab.group_id())
} }
fn tab_state<'a>(
snapshot: &'a ely_browser_core::BrowserSnapshot,
tab_id: &ely_domain::TabId,
) -> Option<&'a TabState> {
snapshot.tabs.iter().find(|tab| tab.id() == tab_id).map(|tab| tab.state())
}
+17
View File
@@ -86,3 +86,20 @@ Domain auto grouping keeps manual groups intact and groups matching ungrouped ho
│ servo.org │ │ │ servo.org │ │
└──────────────────────────────┴───────────────────────────────────────────────┘ └──────────────────────────────┴───────────────────────────────────────────────┘
``` ```
Group sleep applies the sleeping state to every tab in the active group:
```text
┌──────────────────────────────────────────────────────────────────────────────┐
│ ELY Browser [ >sleep-tab-group............................. ] [pin] [*] [+] │
├──────────────────────────────┬───────────────────────────────────────────────┤
│ Tabs │ Sleeping Tab │
│ [folder] Docs │ Sleeping https://example.com/b │
│ 2 tabs - Expanded │ │
│ example.com │ URL https://example.com/b │
│ example.com │ Title example.com │
│ example.com │ Session Page session remains attached │
│ example.com │ │
│ servo.org │ [Restore] │
└──────────────────────────────┴───────────────────────────────────────────────┘
```