mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-31 15:49:48 +00:00
#1458: name the key that turns auto layout off
`{"layoutMode": "NONE", "wrap": true}` was refused with a message
naming `layout`, a key the call didn't have. The error now names the
key the call used.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b45c41a02c
commit
f98da27882
2 files changed
+7
-8
No files matched your search
@@ -267,7 +267,9 @@ fn auto_layout_keys_beside_no_auto_layout_are_refused() {
|
||||
assert!(e.contains("turns auto layout off"), "{props}: {e}");
|
||||
}
|
||||
let e = s.execute("node.set", &json!({"id": f, "props": {"layout": null, "gap": 8, "padding": 4}})).unwrap_err().to_string();
|
||||
assert!(e.contains("`gap`, `padding` are auto layout properties"), "{e}");
|
||||
assert!(e.contains("`gap`, `padding` are auto layout properties, and `layout` in the same call"), "{e}");
|
||||
let e = s.execute("node.set", &json!({"id": f, "props": {"layoutMode": "NONE", "wrap": true}})).unwrap_err().to_string();
|
||||
assert!(e.contains("`wrap` is an auto layout property, and `layoutMode` in the same call"), "{e}");
|
||||
// Without other auto layout keys, `layout: null` still removes it.
|
||||
set(&mut s, f, json!({"layout": "vertical", "gap": 8}));
|
||||
set(&mut s, f, json!({"layout": null, "name": "Plain"}));
|
||||
|
||||
@@ -403,15 +403,12 @@ fn apply_order(k: &str) -> u8 {
|
||||
/// would turn it back on (`layout_mut`), so the call is refused rather than one of them losing.
|
||||
fn layout_keys_beside_none(cmd: &str, props: &Map<String, Value>) -> Result<()> {
|
||||
let off = ["layout", "layoutMode"]
|
||||
.iter()
|
||||
.filter_map(|k| props.get(*k))
|
||||
.any(|v| v.is_null() || v.as_str().is_some_and(|s| s.eq_ignore_ascii_case("none")));
|
||||
.into_iter()
|
||||
.find(|k| props.get(*k).is_some_and(|v| v.is_null() || v.as_str().is_some_and(|s| s.eq_ignore_ascii_case("none"))));
|
||||
let tuning: Vec<String> = props.keys().filter(|k| LAYOUT_KEYS.contains(&k.as_str())).map(|k| format!("`{k}`")).collect();
|
||||
if !off || tuning.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let Some(off) = off.filter(|_| !tuning.is_empty()) else { return Ok(()) };
|
||||
let (what, are) = if tuning.len() == 1 { ("an auto layout property", "is") } else { ("auto layout properties", "are") };
|
||||
Err(bad(cmd, format!("{} {are} {what}, and `layout` in the same call turns auto layout off", tuning.join(", "))))
|
||||
Err(bad(cmd, format!("{} {are} {what}, and `{off}` in the same call turns auto layout off", tuning.join(", "))))
|
||||
}
|
||||
|
||||
/// An explicit width (`is_w`) or height makes hugging or filling on that axis fixed, like typing
|
||||
|
||||
Reference in new issue
Block a user