mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-26 10:47:11 -06:00
Review: Layer Options reuses the translated id messages; ROADMAP (#1077)
The new id errors reuse messages the catalogs already translate (`ids` must be an array of object ids, object ids are non-negative integers, no such layer or object), so complete_languages_translate_every_message keeps passing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d47857a20f
commit
a031ff6c7b
+1
-1
File diff suppressed because one or more lines are too long
@@ -54,21 +54,20 @@ fn fields_of(n: &Node) -> serde_json::Map<String, Value> {
|
||||
/// the current layer), filled in from the first.
|
||||
pub fn open(app: &mut VectorcraftApp, p: &Value) -> Result<Value, String> {
|
||||
let st = app.session.active().ok_or("no document open")?;
|
||||
let parse_id = |value: &Value| -> Result<NodeId, String> {
|
||||
let id = NodeId(value.as_u64().ok_or_else(|| format!("invalid layer or object id: {value}"))?);
|
||||
st.doc.node(id).ok_or_else(|| format!("no such layer or object id: {}", id.0))?;
|
||||
Ok(id)
|
||||
// Rows given are used as given: a malformed or unknown id fails rather than being skipped or
|
||||
// the dialog opening on the highlighted rows instead.
|
||||
let row = |v: &Value| -> Result<NodeId, String> {
|
||||
let id = NodeId(v.as_u64().ok_or_else(|| format!("object ids are non-negative integers, not {v}"))?);
|
||||
st.doc.node(id).map(|_| id).ok_or_else(|| "no such layer or object".to_string())
|
||||
};
|
||||
let ids: Vec<NodeId> = match p.get("ids") {
|
||||
Some(Value::Array(values)) => values.iter().map(parse_id).collect::<Result<_, _>>()?,
|
||||
Some(_) => return Err("`ids` must be an array of layer or object ids".into()),
|
||||
None => match p.get("id") {
|
||||
Some(value) => vec![parse_id(value)?],
|
||||
None => {
|
||||
let rows = st.highlighted_rows();
|
||||
if rows.is_empty() { st.current_layer().into_iter().collect() } else { rows }
|
||||
}
|
||||
},
|
||||
let ids: Vec<NodeId> = match (p.get("ids"), p.get("id")) {
|
||||
(Some(Value::Array(a)), _) => a.iter().map(row).collect::<Result<_, _>>()?,
|
||||
(Some(v), _) => return Err(format!("`ids` must be an array of object ids, not {v}")),
|
||||
(None, Some(v)) => vec![row(v)?],
|
||||
(None, None) => {
|
||||
let rows = st.highlighted_rows();
|
||||
if rows.is_empty() { st.current_layer().into_iter().collect() } else { rows }
|
||||
}
|
||||
};
|
||||
let first = ids.first().and_then(|id| st.doc.node(*id)).ok_or("no such layer or object")?;
|
||||
let mut f = fields_of(first);
|
||||
@@ -265,13 +264,9 @@ mod tests {
|
||||
fn invalid_layer_options_targets_do_not_open_a_partial_dialog() {
|
||||
let mut app = app();
|
||||
let id = app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap();
|
||||
for params in [
|
||||
json!({"ids": [id, "invalid"]}),
|
||||
json!({"ids": [id, 999999]}),
|
||||
json!({"ids": "invalid"}),
|
||||
json!({"id": "invalid"}),
|
||||
json!({"id": null}),
|
||||
] {
|
||||
for params in
|
||||
[json!({"ids": [id, "invalid"]}), json!({"ids": [id, 999999]}), json!({"ids": "invalid"}), json!({"id": "invalid"}), json!({"id": null})]
|
||||
{
|
||||
assert!(app.run("ui.layerOptions", params.clone()).is_err(), "accepted {params}");
|
||||
assert!(app.ui.dialog.is_none(), "opened partial options for {params}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user