diff --git a/crates/ui-egui/src/panel_docking/tests.rs b/crates/ui-egui/src/panel_docking/tests.rs index afae95ca0..1b8b1a168 100644 --- a/crates/ui-egui/src/panel_docking/tests.rs +++ b/crates/ui-egui/src/panel_docking/tests.rs @@ -321,6 +321,13 @@ fn the_tools_panel_docks_on_the_right_left_of_the_panels() { h.app.run("window.panel.float", json!({"panel": "tools"})).unwrap(); assert_eq!(h.app.run("window.panel.dock", json!({"panel": "tools"})).unwrap()["side"], "right", "back on the side it docked at last"); assert!(h.app.run("window.panel.dock", json!({"panel": "tools", "side": "top"})).is_err()); + // A side that isn't text is an error too, not the last side: it leaves Tools where it is. + h.app.run("window.panel.float", json!({"panel": "tools"})).unwrap(); + for side in [json!(5), json!(true), json!(["left"])] { + assert!(h.app.run("window.panel.dock", json!({"panel": "tools", "side": side})).is_err(), "{side}"); + assert!(h.app.ui.toolbar_pos.is_some(), "still floating after side {side}"); + } + assert_eq!(h.app.run("window.panel.dock", json!({"panel": "tools", "side": null})).unwrap()["side"], "right", "null: the last side"); } /// The docked Tools panel as last drawn. diff --git a/crates/ui-egui/src/tools_float.rs b/crates/ui-egui/src/tools_float.rs index 2781e4232..0cc643342 100644 --- a/crates/ui-egui/src/tools_float.rs +++ b/crates/ui-egui/src/tools_float.rs @@ -219,12 +219,14 @@ pub(crate) fn command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option Ok(app.ui.toolbar_right), + let right = match p.get("side") { + None | Some(Value::Null) => Ok(app.ui.toolbar_right), // `Start` and `End`, as panels take them, too. - Some(s) if s.eq_ignore_ascii_case("left") || s.eq_ignore_ascii_case("start") => Ok(false), - Some(s) if s.eq_ignore_ascii_case("right") || s.eq_ignore_ascii_case("end") => Ok(true), - Some(s) => Err(format!("side is left or right, not `{s}`")), + Some(Value::String(s)) if s.eq_ignore_ascii_case("left") || s.eq_ignore_ascii_case("start") => Ok(false), + Some(Value::String(s)) if s.eq_ignore_ascii_case("right") || s.eq_ignore_ascii_case("end") => Ok(true), + Some(Value::String(s)) => Err(format!("side is left or right, not `{s}`")), + // A number, a list…: an error, not the last side. + Some(v) => Err(format!("side is left or right, not `{v}`")), }; Some(position(p).and_then(|at| { let right = right?;