mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 09:26:43 +00:00
Apply panel copy-name setting to the new artboard duplication path
This commit is contained in:
1 parent
44c52a013a
commit
cfe712c340
2 files changed
+22
-1
No files matched your search
@@ -424,6 +424,7 @@ fn add_beside(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
};
|
||||
let grown = |len: u32, by: i32| (i64::from(len) + i64::from(by)).clamp(1, 300_000) as u32;
|
||||
let label = if duplicate { "Duplicate Artboard" } else { "New Artboard" };
|
||||
let add_copy = crate::commands::layer_panel_option(s, "addCopyToCopiedLayersAndGroups", true);
|
||||
let (nid, rect) = s.edit(label, |doc, active| {
|
||||
if (sx, sy) != (0, 0) {
|
||||
crate::image_cmds::translate_doc(doc, cmd, sx, sy)?;
|
||||
@@ -438,7 +439,7 @@ fn add_beside(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let nid = if duplicate {
|
||||
let src_rect = doc.layer(id).and_then(Layer::artboard).map(|a| a.rect).ok_or(EngineError::NoLayer(id))?;
|
||||
let (dx, dy) = (rect.x0.saturating_sub(src_rect.x0), rect.y0.saturating_sub(src_rect.y0));
|
||||
let copy = crate::commands::layer_copy(doc, id)?;
|
||||
let copy = crate::commands::layer_copy(doc, id, add_copy)?;
|
||||
let nid = doc.insert_above(Some(id), copy);
|
||||
// Grow the canvas first, so shapes on the board re-render uncut where they land.
|
||||
let fit = |len: u32, edge: i32| i64::from(len).max(i64::from(edge)).clamp(1, 300_000) as u32;
|
||||
|
||||
@@ -585,3 +585,23 @@ fn add_beside_places_a_board_on_each_side_and_alt_duplicates_contents() {
|
||||
assert_eq!(doc(&s).size, before);
|
||||
assert!(s.execute("layer.artboard.addBeside", json!({"side": "diagonal"})).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_beside_duplicate_honors_panel_copy_name_preference() {
|
||||
for add_copy in [false, true] {
|
||||
let mut s = session(8);
|
||||
let id = board_with_square(&mut s);
|
||||
let name = doc(&s).layer(id).unwrap().name.clone();
|
||||
s.edit_prefs(|prefs| {
|
||||
prefs.dialogs.insert("ui.layersPanelOptions".into(), json!({"addCopyToCopiedLayersAndGroups": add_copy}));
|
||||
});
|
||||
let before = doc(&s).clone();
|
||||
let result = s.execute("layer.artboard.addBeside", json!({"layer": id.0, "side": "bottom", "duplicate": true})).unwrap();
|
||||
let copy = LayerId(result["layer"].as_u64().unwrap());
|
||||
let expected = if add_copy { before.copy_name(&name) } else { name };
|
||||
assert_eq!(doc(&s).layer(copy).unwrap().name, expected);
|
||||
assert!(red_at(&s, 15, 155), "the copied artboard retains its contents");
|
||||
s.undo();
|
||||
assert_eq!(doc(&s), &before);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user