From d71cdfa3ca9f400f476c85a334bf5153b7861ecd Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 2 Nov 2026 11:35:32 +0700 Subject: [PATCH] Undo: never leave a removed effect selected Undoing an effect's add or duplicate took the selected effect away and left the selection on it, so the row lost its highlight and strokes had no target. The selection now falls back to the stack the effect was in. --- crates/engine/src/session.rs | 8 ++++++++ crates/engine/tests/content_effects.rs | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/crates/engine/src/session.rs b/crates/engine/src/session.rs index 14891a8f..baf012b6 100644 --- a/crates/engine/src/session.rs +++ b/crates/engine/src/session.rs @@ -629,6 +629,14 @@ impl Session { self.modified = true; self.revision = self.revision.wrapping_add(1); self.invalidate_changed(other); + // An undone add or duplicate takes the selected effect away: select the stack it was in. + if let StackTarget::Effect(e) = self.target + && self.doc.project.effect(e).is_none() + { + let p = &other.project; + let content = p.effect(e).and_then(|(owner, _)| p.layers.get(&owner)).is_some_and(|l| l.content_effects.iter().any(|x| x.id == e)); + self.target = if content { StackTarget::Content } else { StackTarget::Mask }; + } } // ----------------------------------------------------------------------------------------- diff --git a/crates/engine/tests/content_effects.rs b/crates/engine/tests/content_effects.rs index d67300f7..dca2378b 100644 --- a/crates/engine/tests/content_effects.rs +++ b/crates/engine/tests/content_effects.rs @@ -139,6 +139,10 @@ fn effects_move_within_their_stack_and_duplicate_with_their_pixels() { assert_eq!(order(&s), [fill, paint, copy]); assert_eq!(s.target, StackTarget::Effect(LayerId(copy))); assert!(s.doc.project.effect(LayerId(copy)).unwrap().1.name.ends_with(" copy")); + // Undoing it leaves no missing effect selected, but the stack it was in. + execute(&mut s, "edit.undo", &Value::Null).unwrap(); + assert_eq!(s.target, StackTarget::Content); + execute(&mut s, "edit.redo", &Value::Null).unwrap(); execute(&mut s, "effect.remove", &json!({"effect": paint})).unwrap(); assert!(center(&mut s, Channel::Roughness)[0] > 0.85, "the copy keeps the strokes"); assert!(execute(&mut s, "effect.duplicate", &json!({"effect": 999_999})).is_err());