mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
fix(engine): turn symmetry off when the work path is deleted by any alias (#17384)
path.delete treats "work", "" and "Work Path" as the work path, while symmetry stores its source as "work", so deleting it as "Work Path" or "" left symmetry mirroring a path that no longer exists. Normalise the deleted name before comparing it with the symmetry's source. Co-Authored-By: Codebuff <[email protected]>
This commit is contained in:
1 parent
01286848e5
commit
312c7cbf71
2 files changed
+20
-2
No files matched your search
@@ -46,6 +46,21 @@ fn deleting_the_symmetry_path_turns_symmetry_off_and_undo_brings_it_back() {
|
||||
assert!(symmetry(&s).is_null(), "redo deletes the path again, so symmetry is off again");
|
||||
}
|
||||
|
||||
/// The work path answers to "work", "" and "Work Path" in `path.delete`, while symmetry stores
|
||||
/// it as "work"; every alias must still turn symmetry off.
|
||||
#[test]
|
||||
fn deleting_the_work_path_by_an_alias_turns_symmetry_off_too() {
|
||||
for alias in ["Work Path", ""] {
|
||||
let mut s = session();
|
||||
s.execute("path.set", json!({"name": "work", "path": {"subpaths": [{"knots": [[100, 50], [200, 100]]}]}})).unwrap();
|
||||
s.execute("paint.symmetryFromPath", json!({"name": "work"})).unwrap();
|
||||
s.execute("path.delete", json!({"name": alias})).unwrap();
|
||||
assert!(symmetry(&s).is_null(), "{alias:?} deletes the work path, so symmetry is off");
|
||||
assert!(s.undo());
|
||||
assert_eq!(symmetry(&s)["source"], "work", "{alias:?}: undo brings the symmetry back");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deleting_the_work_path_turns_symmetry_off_too() {
|
||||
let mut s = session();
|
||||
|
||||
@@ -141,8 +141,11 @@ pub(super) fn path_set(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
|
||||
pub(super) fn path_delete(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let name = p.get("name").and_then(Value::as_str).map(str::to_string);
|
||||
// Deleting the path that painting symmetry mirrors across leaves symmetry off (#17384).
|
||||
let symmetry = crate::symmetry_cmds::symmetry_before_path_delete(s, name.as_deref().unwrap_or("work"));
|
||||
// Deleting the path that painting symmetry mirrors across leaves symmetry off (#17384). The
|
||||
// work path answers to "work", "" and "Work Path", while symmetry stores it as "work".
|
||||
let deleted = name.as_deref().unwrap_or("work");
|
||||
let source = if is_work(Some(deleted)) { "work" } else { deleted };
|
||||
let symmetry = crate::symmetry_cmds::symmetry_before_path_delete(s, source);
|
||||
s.edit("Delete Path", |doc, _| {
|
||||
if is_work(name.as_deref()) {
|
||||
return doc.work_path.take().map(|_| ()).ok_or_else(|| EngineError::Other("no work path".into()));
|
||||
|
||||
Reference in new issue
Block a user