diff --git a/crates/behavior/src/dock/action.rs b/crates/behavior/src/dock/action.rs index 8075b7bf4..825e63292 100644 --- a/crates/behavior/src/dock/action.rs +++ b/crates/behavior/src/dock/action.rs @@ -93,6 +93,11 @@ pub struct Location
{
/// restoring creates a new group, column, dock or window for the panel.
#[serde(default)]
pub group: Option ,
}
/// Groups, columns and floating windows are named by a panel they contain.
@@ -340,7 +345,7 @@ pub enum Action {
impl Location {
/// A location relative to `anchor` by `placement`, with no recorded sizes or siblings.
pub fn new(anchor: Option , placement: DockPlacement ) -> Self {
- Self { floating: None, anchor, placement, size: None, stack: None, sibling: Vec::new(), group: None }
+ Self { floating: None, anchor, placement, size: None, stack: None, sibling: Vec::new(), group: None, closed_with: Vec::new() }
}
}
diff --git a/crates/behavior/src/dock/inner.rs b/crates/behavior/src/dock/inner.rs
index bb620b8f5..93510d78a 100644
--- a/crates/behavior/src/dock/inner.rs
+++ b/crates/behavior/src/dock/inner.rs
@@ -554,7 +554,7 @@ pub(super) fn group_location ) -> Option<&P> {
diff --git a/crates/behavior/src/dock/workspace.rs b/crates/behavior/src/dock/workspace.rs
index 5aba1f0b5..6f18bf113 100644
--- a/crates/behavior/src/dock/workspace.rs
+++ b/crates/behavior/src/dock/workspace.rs
@@ -12,7 +12,7 @@ use super::{
DockSide,
action::{Action, DockPlacement, Location},
edit::tree_panels,
- groups::{Column, DockEdge, PanelPlace, Target},
+ groups::{Column, DockEdge, PanelPlace, Target, Unit},
layout::Layout,
limits::MAX_PANELS,
node::Node,
@@ -163,7 +163,7 @@ impl Workspace {
impl {
/// Check the version, the layout, that every hidden panel is hidden once and absent
- /// from the layout, and that the floated records are bounded and one per panel.
+ /// from the layout and its record is bounded, and that the floated records are bounded and one per panel.
pub fn validate(&self) -> Result<(), DockError> {
if self.version > Self::VERSION {
return Err(DockError::UnsupportedVersion);
@@ -174,10 +174,13 @@ impl {
}
let visible: HashSet<&P> = self.layout.panels().into_iter().collect();
let mut seen = HashSet::new();
- for (panel, _) in &self.hidden {
+ for (panel, location) in &self.hidden {
if visible.contains(panel) || !seen.insert(panel) {
return Err(DockError::DuplicatePanel);
}
+ if location.closed_with.len() > MAX_PANELS {
+ return Err(DockError::LimitExceeded);
+ }
}
if self.floated.len() > MAX_PANELS {
return Err(DockError::LimitExceeded);
@@ -211,8 +214,11 @@ impl {
let policy = |panel: &P| if locked { permissions(panel).locked() } else { permissions(panel) };
let mut proposed = self.clone();
let mut all_closed = Vec::new();
+ // The group of each panel as it closes, in closing order.
+ let mut closing_groups = Vec::new();
for action in actions {
let closed = proposed.layout.closed_by(&action)?;
+ closing_groups.extend(closed.iter().map(|panel| proposed.layout.members(panel, Unit::Group).unwrap_or_else(|_| vec![panel.clone()])));
let locations = close_locations(&proposed.layout, &closed);
let before = proposed.layout.clone();
// Opening a hidden panel puts it back where it was.
@@ -240,6 +246,7 @@ impl {
proposed.hidden.retain(|(p, _)| !visible.contains(p));
let mut seen = HashSet::new();
all_closed.retain(|p| !visible.contains(p) && seen.insert(p.clone()));
+ proposed.record_closed_together(&all_closed, &closing_groups);
proposed.validate()?;
let Workspace { layout, hidden, floated, .. } = proposed;
(self.layout, self.hidden, self.floated) = (layout, hidden, floated);
@@ -248,10 +255,11 @@ impl {
}
/// Show or hide one panel. Showing restores its recorded location, following the chain of
- /// hidden anchors when its own anchor is hidden too; otherwise it opens as
- /// [`Action::Open`] with `fallback` as the anchor, following `permissions`. The hidden
- /// panels on that chain reopen beside it later, so a group or window closed one panel at a
- /// time comes back as one.
+ /// hidden anchors when its own anchor is hidden too, and brings back the hidden panels of its
+ /// group that closed with it in one batch (Close Tab Group, a preset) as tabs of its group;
+ /// otherwise it opens as [`Action::Open`] with `fallback` as the anchor, following
+ /// `permissions`. The other hidden panels on that chain reopen beside it later, so a group or
+ /// window closed one panel at a time comes back as one.
/// A shown panel becomes the active tab of its group. Hiding follows `permissions` and
/// `locked`, as [`Self::apply`] does, so a protected canvas stays shown.
pub fn set_visible(
@@ -276,29 +284,91 @@ impl {
self.apply_all([open, Action::Activate { panel }], locked, permissions).map(drop)
}
- /// Restore a hidden `panel` to its recorded place and make it the active tab. `Ok(false)` when the record
- /// cannot be restored, or the place it restores to refuses the panel under `permissions`; the workspace stays
- /// as it was and the caller opens the panel by the ordinary, checked path.
+ /// Restore a hidden `panel` to its recorded place, with the hidden panels closed with it, and make it the
+ /// active tab. The set is restored in group order, each panel by its own record, so the group comes back in
+ /// the order it had; a panel closed with it whose place refuses it stays hidden. `Ok(false)` when `panel`'s
+ /// record cannot be restored, or the place it restores to refuses the panel under `permissions`; the workspace
+ /// stays as it was and the caller opens the panel by the ordinary, checked path.
fn reopen(&mut self, panel: &P, permissions: &impl Fn(&P) -> Permissions) -> Result {
+ let record = |p: &P| self.hidden.iter().find(|(q, _)| q == p).map(|(_, location)| location);
+ let mut seen = HashSet::new();
+ let together: Vec = record(panel)
+ .map(|location| &location.closed_with[..])
+ .unwrap_or_default()
+ .iter()
+ .filter(|&p| p == panel || record(p).is_some_and(|location| location.closed_with.contains(panel)))
+ .filter(|&p| seen.insert(p))
+ .cloned()
+ .collect();
+ if together.len() > 1 && together.contains(panel) { together } else { vec![panel.clone()] }
+ }
+
+ /// Records on the hidden panels `closed`, which this batch closed, the panels of their group that closed with
+ /// them. `groups` holds each closing panel's group as it closed, in closing order. The closed panels of one
+ /// group, or of groups that share one, form one set in the order the groups name them.
+ fn record_closed_together(&mut self, closed: &[P], groups: &[Vec ]) {
+ let closed: HashSet<&P> = closed.iter().collect();
+ let mut sets: Vec = joined.into_iter().flatten().collect();
+ for panel in members {
+ if !set.contains(panel) {
+ set.push(panel.clone());
+ }
+ }
+ sets = rest;
+ if !set.is_empty() {
+ sets.push(set);
+ }
+ }
+ for set in sets.into_iter().filter(|set| set.len() > 1) {
+ for (panel, location) in &mut self.hidden {
+ if set.contains(panel) {
+ location.closed_with.clone_from(&set);
+ }
+ }
}
- layout.apply(Action::Activate { panel: panel.clone() })?;
- self.layout = layout;
- self.hidden = trial.hidden;
- self.hidden.retain(|(p, _)| p != panel);
- Ok(true)
}
/// Update the floated records after an action that turned `before` into the current layout: drop the records of
diff --git a/crates/behavior/tests/dock_apply.rs b/crates/behavior/tests/dock_apply.rs
index c4461067d..b3bad10d0 100644
--- a/crates/behavior/tests/dock_apply.rs
+++ b/crates/behavior/tests/dock_apply.rs
@@ -188,6 +188,42 @@ fn opening_a_closed_floating_panel_restores_its_window_place() {
assert_eq!(group_members(workspace.layout(), 11), [11, 12, 50]);
}
+/// The active tab of the dock or floating group holding `panel`.
+fn front(layout: &Layout