mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 12:32:10 +01:00
Merge pull request #3456 from dotCooCoo/fix/dock-float-closed-keeps-place
dock: Action::Float of a closed panel keeps the docked place it would reopen at
This commit is contained in:
2 files changed
+47
-2
No files matched your search
@@ -41,8 +41,8 @@ pub struct Workspace<P> {
|
||||
/// goes back.
|
||||
#[serde(default)]
|
||||
hidden: Vec<(P, Location<P>)>,
|
||||
/// Floating panels with the docked location each one left, so Dock Panel can return it. Saved with the
|
||||
/// workspace.
|
||||
/// Floating panels with the docked location each one left, so Dock Panel can return it; a closed panel that
|
||||
/// floats records the place it would reopen at. Saved with the workspace.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
floated: Vec<(P, Location<P>)>,
|
||||
/// Counts the replacements of this live workspace. Not saved, and not part of equality.
|
||||
@@ -264,6 +264,16 @@ impl<P: Clone + Eq + Hash> Workspace<P> {
|
||||
Action::Open { panel, .. } if proposed.hidden.iter().any(|(p, _)| p == panel) => proposed.reopen(panel, &policy)?,
|
||||
_ => false,
|
||||
};
|
||||
// Floating a hidden panel records the docked place it would reopen at, without reopening it there. A panel
|
||||
// that would reopen in a floating window has no docked place.
|
||||
let hidden_place = match &action {
|
||||
Action::Float { panel, .. } if !proposed.layout.contains(panel) && proposed.hidden.iter().any(|(p, _)| p == panel) => proposed
|
||||
.restored(panel, &policy)
|
||||
.filter(|restored| !floats(&restored.layout, panel))
|
||||
.and_then(|restored| restored.layout.location(panel).ok())
|
||||
.map(|location| (panel.clone(), location)),
|
||||
_ => None,
|
||||
};
|
||||
if !reopened {
|
||||
// SetNative records where the window system has a floating window, so a lock
|
||||
// does not refuse it.
|
||||
@@ -278,6 +288,12 @@ impl<P: Clone + Eq + Hash> Workspace<P> {
|
||||
proposed.hidden.push((panel, location));
|
||||
}
|
||||
proposed.track_floated(&before);
|
||||
if let Some((panel, location)) = hidden_place
|
||||
&& floats(&proposed.layout, &panel)
|
||||
&& !proposed.floated.iter().any(|(p, _)| p == &panel)
|
||||
{
|
||||
proposed.floated.push((panel, location));
|
||||
}
|
||||
all_closed.extend(closed);
|
||||
}
|
||||
let visible: HashSet<P> = proposed.layout.panels().into_iter().cloned().collect();
|
||||
|
||||
@@ -241,6 +241,35 @@ fn a_floated_panel_keeps_where_it_was_docked_until_it_docks_or_closes() {
|
||||
assert!(workspace.floated().is_empty(), "closing drops the record");
|
||||
}
|
||||
|
||||
/// A closed panel that floats by itself records the place it would reopen at, as opening it first records, and its old
|
||||
/// group keeps its front tab; docking it then returns it to that group at its old index.
|
||||
#[test]
|
||||
fn a_closed_panel_that_floats_keeps_its_docked_place_and_its_old_group_keeps_its_front_tab() {
|
||||
let float = Action::float(2, rect(10.0, 10.0, 200.0, 200.0));
|
||||
let mut opened = Workspace::new(docked());
|
||||
opened.apply(Action::close(2), false, allow).unwrap();
|
||||
opened.apply_all([Action::open(2, None), float.clone()], false, allow).unwrap();
|
||||
|
||||
let mut workspace = Workspace::new(docked());
|
||||
workspace.apply(Action::close(2), false, allow).unwrap();
|
||||
workspace.apply(float, false, allow).unwrap();
|
||||
let layout = workspace.layout();
|
||||
assert!(matches!(layout.place(&2), Some(PanelPlace::Floating { .. })));
|
||||
assert_eq!(group_members(layout, 3), [3]);
|
||||
assert_eq!(front(layout, 3), 3, "the old group keeps its front tab");
|
||||
assert_eq!(workspace.floated(), opened.floated(), "the record matches the one opening it first gives");
|
||||
|
||||
let [(_, location)] = workspace.floated() else { panic!("one record: {:?}", workspace.floated()) };
|
||||
let back = Action::move_beside(2, location.anchor.unwrap(), location.placement.clone());
|
||||
workspace.apply(back, false, allow).unwrap();
|
||||
assert_eq!(end_dock(workspace.layout())[0].groups[0].panels, [2, 3], "Dock Panel returns it to its old index");
|
||||
|
||||
let mut workspace = Workspace::new(docked());
|
||||
workspace.apply(Action::close(6), false, allow).unwrap();
|
||||
workspace.apply(Action::float(6, rect(10.0, 10.0, 200.0, 200.0)), false, allow).unwrap();
|
||||
assert!(workspace.floated().is_empty(), "a panel closed from a floating window has no docked place");
|
||||
}
|
||||
|
||||
/// Canvas 1; an end dock with an expanded column [2] and a collapsed column [3], [4]; a floating window [6].
|
||||
fn columns() -> Layout<u32> {
|
||||
let dock = Node::dock(DockEdge::End, vec![Column::new(vec![g(&[2], 0)]), Column::new(vec![g(&[3], 0), g(&[4], 0)]).with_iconic(true)]);
|
||||
|
||||
Reference in new issue
Block a user