Add domain tab auto grouping
This commit is contained in:
@@ -195,6 +195,10 @@ impl BrowserCore {
|
||||
"split-tab-group" | "split tab group" | "tab-group-to-split" | "tab group to split" => {
|
||||
Ok(self.split_active_tab_group()?.is_some())
|
||||
}
|
||||
"auto-group-domains"
|
||||
| "auto group domains"
|
||||
| "auto-group-domain-tabs"
|
||||
| "auto group domain tabs" => Ok(self.auto_group_active_space_tabs_by_domain()? > 0),
|
||||
"group-split-view"
|
||||
| "group split view"
|
||||
| "split-view-to-group"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use ely_domain::{
|
||||
BrowserTab, MAX_SPLIT_PANES, SpaceId, SplitAxis, SplitId, SplitLayout, SplitPane, TabGroup,
|
||||
TabGroupId, TabId,
|
||||
@@ -15,6 +17,25 @@ impl BrowserCore {
|
||||
Ok(group_id)
|
||||
}
|
||||
|
||||
pub fn auto_group_active_space_tabs_by_domain(&mut self) -> Result<usize, CoreError> {
|
||||
let domain_tab_ids = self.active_space_domain_tab_ids();
|
||||
let mut grouped_count = 0;
|
||||
|
||||
for (domain, tab_ids) in domain_tab_ids {
|
||||
if tab_ids.len() < 2 {
|
||||
continue;
|
||||
}
|
||||
|
||||
let group_id = self.find_or_create_active_space_tab_group(domain)?;
|
||||
for tab_id in tab_ids {
|
||||
self.assign_tab_to_group(&tab_id, &group_id)?;
|
||||
grouped_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(grouped_count)
|
||||
}
|
||||
|
||||
pub fn assign_tab_to_group(
|
||||
&mut self,
|
||||
tab_id: &TabId,
|
||||
@@ -210,6 +231,26 @@ impl BrowserCore {
|
||||
.map(|group| group.id().clone())
|
||||
}
|
||||
|
||||
fn active_space_domain_tab_ids(&self) -> BTreeMap<String, Vec<TabId>> {
|
||||
let mut domain_tab_ids = BTreeMap::new();
|
||||
for tab in self.tabs.iter().filter(|tab| self.tab_is_domain_group_candidate(tab)) {
|
||||
let Some(domain) = domain_group_name(tab) else {
|
||||
continue;
|
||||
};
|
||||
domain_tab_ids.entry(domain).or_insert_with(Vec::new).push(tab.id().clone());
|
||||
}
|
||||
|
||||
domain_tab_ids
|
||||
}
|
||||
|
||||
fn tab_is_domain_group_candidate(&self, tab: &BrowserTab) -> bool {
|
||||
tab.space_id() == &self.active_space_id
|
||||
&& tab.group_id().is_none()
|
||||
&& tab.split_id().is_none()
|
||||
&& !tab.flags().favorite
|
||||
&& !tab.flags().pinned
|
||||
}
|
||||
|
||||
fn next_tab_group_sort_key_for_space(&self, space_id: &SpaceId) -> u64 {
|
||||
self.tab_groups
|
||||
.iter()
|
||||
@@ -275,3 +316,11 @@ impl BrowserCore {
|
||||
.ok_or_else(|| CoreError::TabGroupNotFound { id: group_id.clone() })
|
||||
}
|
||||
}
|
||||
|
||||
fn domain_group_name(tab: &BrowserTab) -> Option<String> {
|
||||
if tab.url().as_str().starts_with("ely://") {
|
||||
return None;
|
||||
}
|
||||
|
||||
tab.url().host()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user