mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-09 15:27:02 +00:00
Workspace: window.panel.dock rejects a Tools side that isn't text
side: 5 (or true, or a list) docked Tools on the side it docked at last; it is now an error like any other side but left/right/Start/End, and leaves the panel where it is. null still means the last side.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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?;
|
||||
|
||||
Reference in New Issue
Block a user