Add split view panes

This commit is contained in:
2026-05-08 01:47:19 -04:00
parent ccb3972b75
commit 23b108c8dd
13 changed files with 419 additions and 6 deletions
+7 -1
View File
@@ -1,4 +1,4 @@
use ely_domain::{DomainError, DownloadId, PluginId, ProfileId, SpaceId, TabId};
use ely_domain::{DomainError, DownloadId, PluginId, ProfileId, SpaceId, SplitId, TabId};
use thiserror::Error;
#[derive(Clone, Debug, Error, Eq, PartialEq)]
@@ -12,6 +12,9 @@ pub enum CoreError {
#[error("space not found: {id}")]
SpaceNotFound { id: SpaceId },
#[error("split not found: {id}")]
SplitNotFound { id: SplitId },
#[error("profile not found: {id}")]
ProfileNotFound { id: ProfileId },
@@ -33,6 +36,9 @@ pub enum CoreError {
#[error("favorite limit reached: {limit}")]
FavoriteLimitReached { limit: usize },
#[error("split pane limit reached: {limit}")]
SplitPaneLimitReached { limit: usize },
#[error("browser state has no archived tabs")]
NoArchivedTabs,
+6 -1
View File
@@ -3,7 +3,7 @@ use std::collections::BTreeMap;
use ely_domain::{
ArchivedTab, BookmarkEntry, BrowserTab, DomainError, DownloadEntry, DownloadPolicy,
HistoryEntry, Profile, ProfileId, ProfileKind, ReadingListEntry, SitePermissionAuditEvent,
SitePermissionEntry, Space, SpaceId, SyncStatus, TabId, UrlText,
SitePermissionEntry, Space, SpaceId, SplitLayout, SyncStatus, TabId, UrlText,
};
use crate::CoreError;
@@ -16,6 +16,7 @@ mod plugins;
mod profiles;
mod reading_list;
mod site_permissions;
mod splits;
mod sync;
mod tabs;
@@ -52,6 +53,7 @@ pub struct BrowserSnapshot {
pub site_permission_audit_events: Vec<SitePermissionAuditEvent>,
pub download_entries: Vec<DownloadEntry>,
pub history_entries: Vec<HistoryEntry>,
pub split_layouts: Vec<SplitLayout>,
pub installed_plugins: Vec<InstalledPlugin>,
pub plugin_audit_events: Vec<PluginAuditEvent>,
pub spaces: Vec<Space>,
@@ -78,6 +80,7 @@ pub struct BrowserCore {
site_permission_audit_events: Vec<SitePermissionAuditEvent>,
download_entries: Vec<DownloadEntry>,
history_entries: Vec<HistoryEntry>,
split_layouts: Vec<SplitLayout>,
installed_plugins: Vec<InstalledPlugin>,
plugin_audit_events: Vec<PluginAuditEvent>,
active_space_id: SpaceId,
@@ -126,6 +129,7 @@ impl BrowserCore {
site_permission_audit_events: Vec::new(),
download_entries: Vec::new(),
history_entries: Vec::new(),
split_layouts: Vec::new(),
installed_plugins: Vec::new(),
plugin_audit_events: Vec::new(),
command_query: String::new(),
@@ -211,6 +215,7 @@ impl BrowserCore {
site_permission_audit_events: self.visible_site_permission_audit_events(),
download_entries: self.visible_downloads(),
history_entries: self.visible_history(),
split_layouts: self.visible_split_layouts(),
installed_plugins: self.installed_plugins.clone(),
plugin_audit_events: self.plugin_audit_events.clone(),
spaces: self.spaces.clone(),
@@ -121,6 +121,10 @@ impl BrowserCore {
self.open_tab(self.new_tab_url.clone());
Ok(true)
}
"split-right" | "split right" => {
self.split_active_tab_right()?;
Ok(true)
}
"downloads" | "open-downloads" | "open downloads" => {
self.open_tab(downloads_url()?);
Ok(true)
+101
View File
@@ -0,0 +1,101 @@
use ely_domain::{MAX_SPLIT_PANES, SplitAxis, SplitId, SplitLayout, SplitPane, TabId};
use crate::CoreError;
use super::BrowserCore;
impl BrowserCore {
pub fn split_active_tab_right(&mut self) -> Result<SplitId, CoreError> {
let active_index = self.active_tab_index()?;
let active_tab_id = self.tabs[active_index].id().clone();
let active_space_id = self.tabs[active_index].space_id().clone();
let active_profile_id = self.tabs[active_index].profile_id().clone();
let split_id = self.split_id_for_new_pane(&active_tab_id)?;
let mut new_tab =
self.build_tab_for(active_space_id, active_profile_id, self.new_tab_url.clone());
let new_tab_id = new_tab.id().clone();
new_tab.set_split_id(split_id.clone());
let layout = self
.split_layouts
.iter_mut()
.find(|layout| layout.id() == &split_id)
.ok_or_else(|| CoreError::SplitNotFound { id: split_id.clone() })?;
if !layout.add_pane(SplitPane::new(new_tab_id.clone(), 1)) {
return Err(CoreError::SplitPaneLimitReached { limit: MAX_SPLIT_PANES });
}
let insert_index = self.active_tab_index()? + 1;
self.tabs.insert(insert_index, new_tab);
self.select_tab(&new_tab_id)?;
Ok(split_id)
}
pub(super) fn detach_tab_from_split(&mut self, tab_id: &TabId) {
for tab in self.tabs.iter_mut().filter(|tab| tab.id() == tab_id) {
tab.clear_split_id();
}
for layout in &mut self.split_layouts {
layout.remove_tab(tab_id);
}
let dissolved_split_ids = self
.split_layouts
.iter()
.filter(|layout| layout.pane_count() <= 1)
.map(|layout| layout.id().clone())
.collect::<Vec<_>>();
for split_id in &dissolved_split_ids {
for tab in self.tabs.iter_mut().filter(|tab| tab.split_id() == Some(split_id)) {
tab.clear_split_id();
}
}
self.split_layouts.retain(|layout| layout.pane_count() > 1);
}
pub(super) fn visible_split_layouts(&self) -> Vec<SplitLayout> {
self.split_layouts
.iter()
.filter(|layout| {
layout.panes().iter().all(|pane| {
self.tabs.iter().any(|tab| {
tab.id() == pane.tab_id() && tab.space_id() == &self.active_space_id
})
})
})
.cloned()
.collect()
}
fn split_id_for_new_pane(&mut self, active_tab_id: &TabId) -> Result<SplitId, CoreError> {
if let Some(split_id) = self.active_split_id(active_tab_id) {
if self
.split_layouts
.iter()
.any(|layout| layout.id() == &split_id && layout.pane_count() < MAX_SPLIT_PANES)
{
return Ok(split_id);
}
self.detach_tab_from_split(active_tab_id);
}
let active_index = self.active_tab_index()?;
let layout =
SplitLayout::new(SplitAxis::Horizontal, vec![SplitPane::new(active_tab_id.clone(), 1)]);
let split_id = layout.id().clone();
self.tabs[active_index].set_split_id(split_id.clone());
self.split_layouts.push(layout);
Ok(split_id)
}
fn active_split_id(&self, active_tab_id: &TabId) -> Option<SplitId> {
self.tabs
.iter()
.find(|tab| tab.id() == active_tab_id)
.and_then(|tab| tab.split_id().cloned())
}
}
+6 -2
View File
@@ -40,6 +40,8 @@ impl BrowserCore {
return Ok(tab_id);
}
self.detach_tab_from_split(&tab_id);
let tab_index = self.active_tab_index()?;
self.tabs[tab_index].move_to_space(space_id.clone());
self.active_tabs_by_space.insert(space_id.clone(), tab_id.clone());
self.active_tabs_by_space_profile.remove(&(source_space_id.clone(), profile_id.clone()));
@@ -82,10 +84,12 @@ impl BrowserCore {
.ok_or_else(|| CoreError::TabNotFound { id: tab_id.clone() })?;
let was_active = &self.active_tab_id == tab_id;
let closed_tab = self.tabs.remove(close_index);
let mut closed_tab = self.tabs.remove(close_index);
let closed_space_id = closed_tab.space_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);
closed_tab.clear_split_id();
self.detach_tab_from_split(tab_id);
self.active_tabs_by_space_profile
.remove(&(closed_space_id.clone(), closed_profile_id.clone()));
self.archived_tabs.push(ArchivedTab::new(closed_tab, ArchiveSource::ManualClose));
@@ -270,7 +274,7 @@ impl BrowserCore {
Ok(next_tab_id)
}
fn active_tab_index(&self) -> Result<usize, CoreError> {
pub(super) fn active_tab_index(&self) -> Result<usize, CoreError> {
self.tabs
.iter()
.position(|tab| tab.id() == &self.active_tab_id)
+85
View File
@@ -0,0 +1,85 @@
use std::error::Error;
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
use ely_domain::{CommandIntent, SplitAxis};
#[test]
fn split_right_creates_two_pane_layout() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let first_tab_id = core.active_tab()?.id().clone();
let split_id = core.split_active_tab_right()?;
let snapshot = core.snapshot()?;
let layout = snapshot
.split_layouts
.iter()
.find(|layout| layout.id() == &split_id)
.ok_or("missing split layout")?;
assert_eq!(snapshot.tabs.len(), 2);
assert_eq!(layout.axis(), &SplitAxis::Horizontal);
assert_eq!(layout.pane_count(), 2);
assert_eq!(layout.panes()[0].tab_id(), &first_tab_id);
assert_eq!(layout.panes()[1].tab_id(), &snapshot.active_tab_id);
assert!(snapshot.tabs.iter().all(|tab| tab.split_id() == Some(&split_id)));
Ok(())
}
#[test]
fn split_right_command_focuses_new_pane() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.set_command_query(">split-right");
let intent = core.submit_command()?;
let snapshot = core.snapshot()?;
let active_tab = core.active_tab()?;
assert_eq!(intent, Some(CommandIntent::Command("split-right".to_string())));
assert_eq!(snapshot.tabs.len(), 2);
assert_eq!(snapshot.split_layouts.len(), 1);
assert_eq!(active_tab.url().as_str(), "ely://new-tab");
assert_eq!(snapshot.command_query, "");
Ok(())
}
#[test]
fn closing_split_pane_dissolves_two_pane_layout() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let remaining_tab_id = core.active_tab()?.id().clone();
core.split_active_tab_right()?;
core.close_active_tab()?;
let snapshot = core.snapshot()?;
assert!(snapshot.split_layouts.is_empty());
assert_eq!(snapshot.tabs.len(), 1);
assert_eq!(snapshot.active_tab_id, remaining_tab_id);
assert_eq!(snapshot.tabs[0].split_id(), None);
assert_eq!(snapshot.archived_tabs.len(), 1);
assert_eq!(snapshot.archived_tabs[0].tab().split_id(), None);
Ok(())
}
#[test]
fn moving_split_pane_dissolves_source_layout() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let work_space_id = core.snapshot()?.active_space_id;
let moved_tab_id = {
let research_space_id = core.create_space("Research", "R", 0xf54e00)?;
core.select_space(&work_space_id)?;
core.split_active_tab_right()?;
let moved_tab_id = core.active_tab()?.id().clone();
core.move_active_tab_to_space(&research_space_id)?;
moved_tab_id
};
let research_snapshot = core.snapshot()?;
assert_eq!(research_snapshot.active_tab_id, moved_tab_id);
assert!(research_snapshot.split_layouts.is_empty());
core.select_space(&work_space_id)?;
let work_snapshot = core.snapshot()?;
assert!(work_snapshot.split_layouts.is_empty());
assert!(work_snapshot.tabs.iter().all(|tab| tab.split_id().is_none()));
Ok(())
}