From 5038c1e01aa0836ff75c530efbd6435b0f5234a8 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 22:20:52 -0800 Subject: [PATCH] Panels: a panel that opens in a window of its own floats there directly instead of docking at the end of the main group first, so the docked group keeps Properties in front, as production did window.panel and place_floating opened a panel that has no place in the dock at the end of the main tab group and then floated it out. Opening it made it the group's front tab, and floating it out left the group's last tab, Libraries, in front instead of Properties. --- crates/ui-egui/src/panel_docking.rs | 6 ++++-- crates/ui-egui/src/panel_docking/tests.rs | 24 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs index 11d157bd41..8ec791afdc 100644 --- a/crates/ui-egui/src/panel_docking.rs +++ b/crates/ui-egui/src/panel_docking.rs @@ -934,7 +934,7 @@ fn show_actions(ws: &Workspace, space: &FloatSpace, panel: &str, (None, true) => vec![Action::open(id, first_dock_panel(layout, panel))], (None, false) => { let rect = space.place(space.size_of(&DragUnit::Panel(id.clone()), None)); - vec![Action::open(id.clone(), None), Action::float(id, rect)] + vec![Action::float(id, rect)] } } } @@ -1088,7 +1088,9 @@ pub(crate) fn place_floating(app: &mut VectorcraftApp, panel: &str, pos: egui::P let rect = egui::Rect::from_min_size(pos, egui::vec2(width, floating_height(app, &id))); let layout = layout_of(&app.ui); let mut actions = Vec::new(); - if !layout.contains(&id) { + // A hidden panel goes back to its place first, so Dock Panel returns it there; any other panel floats without joining a + // docked group, which would change that group's front tab. + if !layout.contains(&id) && app.ui.dock_workspace.hidden().iter().any(|(p, _)| p == &id) { actions.push(Action::open(id.clone(), None)); } // A rail's window is a stepped column, which the dock fits to the rail's grid; it keeps the steps it had. diff --git a/crates/ui-egui/src/panel_docking/tests.rs b/crates/ui-egui/src/panel_docking/tests.rs index 2544e8756a..836606c8b2 100644 --- a/crates/ui-egui/src/panel_docking/tests.rs +++ b/crates/ui-egui/src/panel_docking/tests.rs @@ -711,6 +711,30 @@ fn window_menu_panels_without_a_place_open_in_their_icon_group_or_float() { assert!(h.tab("openType").is_some()); } +/// The tab in front of the docked group that holds `panel`. +fn front_of_group(layout: &Layout, panel: &str) -> Option { + dock_columns(layout).into_iter().flat_map(|c| &c.groups).find(|g| g.panels.iter().any(|p| p == panel)).and_then(|g| g.active_panel()).cloned() +} + +#[test] +fn a_panel_that_opens_floating_leaves_the_docked_tabs_as_they_were() { + let mut h = Harness::new(); + assert_eq!(front_of_group(&h.layout(), "properties").as_deref(), Some("properties")); + for panel in ["openType", "docInfo", "attributes", "imageTrace"] { + h.app.run("window.panel", json!({"panel": panel})).unwrap(); + h.frame(vec![]); + let layout = h.layout(); + assert!(floating_window(&layout, panel).is_some(), "{panel} floats"); + assert_eq!(main_panels(&layout), ["properties", "layers", "libraries"], "after {panel}"); + assert_eq!(front_of_group(&layout, "properties").as_deref(), Some("properties"), "Properties stays in front after {panel}"); + } + // A panel placed in a window of its own at a point leaves them as well. + place_floating(&mut h.app, "magicWand", pos2(200.0, 200.0), 0.0).unwrap(); + let layout = h.layout(); + assert!(floating_window(&layout, "magicWand").is_some()); + assert_eq!(front_of_group(&layout, "properties").as_deref(), Some("properties"), "Properties stays in front after a placed panel"); +} + #[test] fn f7_restores_only_tabs_hidden_with_the_group() { let mut h = Harness::new();