Add tab group refresh command
This commit is contained in:
@@ -216,6 +216,9 @@ impl BrowserCore {
|
||||
"sleep-tab-group" | "sleep tab group" | "discard-tab-group" | "discard tab group" => {
|
||||
Ok(self.discard_active_tab_group()?.is_some())
|
||||
}
|
||||
"refresh-tab-group" | "refresh tab group" | "reload-tab-group" | "reload tab group" => {
|
||||
Ok(self.refresh_active_tab_group()?.is_some())
|
||||
}
|
||||
"close-tab-group" | "close tab group" | "archive-tab-group" | "archive tab group" => {
|
||||
Ok(self.close_active_tab_group()?.is_some())
|
||||
}
|
||||
|
||||
@@ -93,6 +93,19 @@ impl BrowserCore {
|
||||
Ok(Some(tab_ids.len()))
|
||||
}
|
||||
|
||||
pub fn refresh_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.refresh_tab(tab_id)?;
|
||||
}
|
||||
|
||||
Ok(Some(tab_ids.len()))
|
||||
}
|
||||
|
||||
pub fn close_active_tab_group(&mut self) -> Result<Option<usize>, CoreError> {
|
||||
let Some(group_id) = self.active_tab_group_id()? else {
|
||||
return Ok(None);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::time::SystemTime;
|
||||
|
||||
use ely_domain::TabId;
|
||||
|
||||
use super::BrowserCore;
|
||||
@@ -42,6 +44,20 @@ impl BrowserCore {
|
||||
self.mark_tab_ready(tab_id)
|
||||
}
|
||||
|
||||
pub(super) fn refresh_tab(&mut self, tab_id: &TabId) -> Result<TabId, CoreError> {
|
||||
{
|
||||
let tab = self
|
||||
.tabs
|
||||
.iter_mut()
|
||||
.find(|tab| tab.id() == tab_id)
|
||||
.ok_or_else(|| CoreError::TabNotFound { id: tab_id.clone() })?;
|
||||
tab.mark_ready();
|
||||
}
|
||||
|
||||
self.record_tab_activity(tab_id, SystemTime::now());
|
||||
Ok(tab_id.clone())
|
||||
}
|
||||
|
||||
fn mark_tab_ready(&mut self, tab_id: &TabId) -> Result<TabId, CoreError> {
|
||||
{
|
||||
let tab = self
|
||||
|
||||
@@ -203,6 +203,46 @@ fn sleep_tab_group_command_preserves_query_without_active_group() -> Result<(),
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refresh_tab_group_command_marks_active_group_tabs_ready() -> 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.crash_tab(&first_group_tab_id)?;
|
||||
core.discard_tab(&second_group_tab_id)?;
|
||||
|
||||
core.set_command_query(">refresh-tab-group");
|
||||
let intent = core.submit_command()?;
|
||||
let snapshot = core.snapshot()?;
|
||||
|
||||
assert_eq!(intent, Some(CommandIntent::Command("refresh-tab-group".to_string())));
|
||||
assert_eq!(snapshot.command_query, "");
|
||||
assert_eq!(snapshot.tab_groups.len(), 1);
|
||||
assert_eq!(tab_state(&snapshot, &first_group_tab_id), Some(&TabState::Ready));
|
||||
assert_eq!(tab_state(&snapshot, &second_group_tab_id), Some(&TabState::Ready));
|
||||
assert_eq!(tab_state(&snapshot, &ungrouped_tab_id), Some(&TabState::Ready));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refresh_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.discard_tab(&tab_id)?;
|
||||
|
||||
core.set_command_query(">refresh-tab-group");
|
||||
let intent = core.submit_command()?;
|
||||
let snapshot = core.snapshot()?;
|
||||
|
||||
assert_eq!(intent, Some(CommandIntent::Command("refresh-tab-group".to_string())));
|
||||
assert_eq!(snapshot.command_query, ">refresh-tab-group");
|
||||
assert_eq!(tab_state(&snapshot, &tab_id), Some(&TabState::Discarded));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn close_tab_group_command_archives_active_group_tabs() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
|
||||
Reference in New Issue
Block a user