Merge pull request #1882

This commit is contained in:
autocraft-bot[bot]
2026-12-04 14:48:40 +00:00
3 changed files with 46 additions and 6 deletions
+3 -3
View File
@@ -234,7 +234,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Change Layout",
["Diagram Design", "Layouts"],
None,
"{id?, kind: list|blockList|hBulletList|process|chevron|verticalProcess|stepUp|cycle|blockCycle|radial|hierarchy|pyramid|invertedPyramid|matrix|titledMatrix|pictureList|pictureCaption|pictureProcess|pictureHList|timeline|venn|target|textCycle|continuousCycle|horizontalHierarchy|gridMatrix|gear|funnel|segmentedCycle|multidirectionalCycle|orgChart|halfCircleOrgChart|cycleMatrix|segmentedPyramid|pie|nameTitleOrgChart|verticalBoxList|trapezoidList|tableList|accentProcess|continuousBlockProcess|bendingProcess|linearVenn|stackedVenn|nestedTarget}",
"{id?, kind: list|blockList|hBulletList|process|chevron|verticalProcess|stepUp|cycle|blockCycle|radial|hierarchy|pyramid|invertedPyramid|matrix|titledMatrix|pictureList|pictureCaption|pictureProcess|pictureHList|timeline|venn|target|textCycle|continuousCycle|horizontalHierarchy|gridMatrix|gear|funnel|segmentedCycle|multidirectionalCycle|orgChart|halfCircleOrgChart|cycleMatrix|segmentedPyramid|pie|nameTitleOrgChart|verticalBoxList|trapezoidList|tableList|accentProcess|continuousBlockProcess|bendingProcess|linearVenn|stackedVenn|nestedTarget} → {id, ids: the regenerated shapes}",
has_diagram,
change_layout
),
@@ -279,7 +279,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Diagram Styles",
["Diagram Design", "Diagram Styles"],
None,
"{id?, style: flat|subtle|intense|outline|polished|inset|cartoon|powder|brick}",
"{id?, style: flat|subtle|intense|outline|polished|inset|cartoon|powder|brick} → {id, ids: the regenerated shapes}",
has_diagram,
change_style
),
@@ -288,7 +288,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Change Colors",
["Diagram Design", "Diagram Styles"],
None,
"{id?, colors: colorful|range23|range34|range45|range56|accent1|…|accent6|accent1Grad|…|accent6Grad}",
"{id?, colors: colorful|range23|range34|range45|range56|accent1|…|accent6|accent1Grad|…|accent6Grad} → {id, ids: the regenerated shapes}",
has_diagram,
change_colors
),
+18 -3
View File
@@ -339,33 +339,47 @@ pub(super) fn set_picture(s: &mut Session, p: &Value) -> Result<Value> {
})
}
/// The answer of a command that regenerated a graphic's shapes: the group's id and its new children's ids.
fn regenerated(s: &Session, gid: ShapeId) -> Value {
let kids: Vec<u32> = match s.doc().ok().and_then(|st| st.shape(gid).map(|g| g.kind.clone())) {
Some(ShapeKind::Group { children, .. }) => children.iter().map(|c| c.id.0).collect(),
_ => vec![],
};
json!({"id": gid.0, "ids": kids})
}
pub(super) fn change_style(s: &mut Session, p: &Value) -> Result<Value> {
const CMD: &str = "smartArt.style";
let v = str_param(p, "style").filter(|k| STYLES.iter().any(|(id, _)| id == k)).ok_or_else(|| bad(CMD, "unknown style"))?.to_string();
let gid = target_group(s, p, CMD)?;
edit_diagram(s, p, CMD, |d| {
if d.style != v {
d.style_xml = None;
}
d.style = v;
Ok(Value::Null)
})
})?;
Ok(regenerated(s, gid))
}
pub(super) fn change_colors(s: &mut Session, p: &Value) -> Result<Value> {
const CMD: &str = "smartArt.colors";
let v = str_param(p, "colors").filter(|k| COLORS.iter().any(|(id, _)| id == k)).ok_or_else(|| bad(CMD, "unknown colours"))?.to_string();
let gid = target_group(s, p, CMD)?;
edit_diagram(s, p, CMD, |d| {
if d.colors != v {
d.colors_xml = None;
}
d.colors = v;
Ok(Value::Null)
})
})?;
Ok(regenerated(s, gid))
}
pub(super) fn change_layout(s: &mut Session, p: &Value) -> Result<Value> {
const CMD: &str = "smartArt.layout";
let kind = str_param(p, "kind").filter(|k| is_kind(k)).ok_or_else(|| bad(CMD, "unknown layout"))?.to_string();
let gid = target_group(s, p, CMD)?;
edit_diagram(s, p, CMD, |d| {
if d.kind != kind {
// PowerPoint's own layout no longer applies.
@@ -374,5 +388,6 @@ pub(super) fn change_layout(s: &mut Session, p: &Value) -> Result<Value> {
}
d.kind = kind;
Ok(Value::Null)
})
})?;
Ok(regenerated(s, gid))
}
+25
View File
@@ -8220,3 +8220,28 @@ fn editor_replacements_report_autocorrection_and_cancel_only_the_open_session()
assert!(std::sync::Arc::ptr_eq(&restored, &s.doc().unwrap().doc));
assert_eq!(s.doc().unwrap().history.undo.len(), undo);
}
#[test]
fn smartart_colors_layout_and_style_answer_the_regenerated_ids() {
let mut s = session();
let r = s.execute("insert.smartArt", &json!({"kind": "process"})).unwrap();
let gid = r["id"].clone();
for (cmd, params) in [
("smartArt.colors", json!({"id": gid, "colors": "colorful"})),
("smartArt.layout", json!({"id": gid, "kind": "cycle"})),
("smartArt.style", json!({"id": gid, "style": "intense"})),
] {
let a = s.execute(cmd, &params).unwrap();
assert_eq!(a["id"], gid, "{cmd}: {a}");
let st = s.doc().unwrap();
let g = st
.doc
.slides
.iter()
.find_map(|sl| deckcraft_model::find_shape(&sl.shapes, deckcraft_model::ShapeId(gid.as_u64().unwrap() as u32)))
.unwrap();
let deckcraft_model::ShapeKind::Group { children, .. } = &g.kind else { panic!("group") };
let kids: Vec<u32> = children.iter().map(|c| c.id.0).collect();
assert_eq!(a["ids"], json!(kids), "{cmd}: {a}");
}
}