Merge pull request #6287 from vecteza/fix/tools-dock-side-type

Workspace: window.panel.dock rejects a Tools side that isn't text
This commit is contained in:
BFlat
2026-11-09 15:02:02 +08:00
committed by GitHub
2 changed files with 14 additions and 5 deletions
@@ -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.
+7 -5
View File
@@ -219,12 +219,14 @@ pub(crate) fn command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<R
return None;
}
// Docking: on the left, or on the right left of the panels (default: the side it docked at last).
let right = match p.get("side").and_then(Value::as_str) {
None => 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?;