mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-22 07:20:45 +01:00
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.
This commit is contained in:
1 parent
0d2f1873cd
commit
d71cdfa3ca
2 files changed
+12
No files matched your search
@@ -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 };
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in new issue
Block a user