mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 12:16:39 +00:00
Live Paint: canceling keeps the defaults a defaultsOnly preview began with
With New Art Has Basic Appearance off and an object selected, canceling an interaction that had previewed a command with defaultsOnly: true replaced the restored defaults with the selection's appearance. Cancel now skips the new-art inheritance for such an interaction.
This commit is contained in:
@@ -373,6 +373,8 @@ impl Session {
|
||||
let outer = std::mem::replace(&mut self.previewing, true);
|
||||
let r = self.execute(cmd, params);
|
||||
self.previewing = outer;
|
||||
// A step inside a batch that changed only the defaults counts as well.
|
||||
let ran_defaults_only = self.defaults_only_ran.is_some();
|
||||
if let Some(paint) = color_mode_paint {
|
||||
self.paint = paint;
|
||||
}
|
||||
@@ -380,6 +382,7 @@ impl Session {
|
||||
let batch_paint = (r.is_ok() && cmd == "command.batch").then(|| self.paint.clone());
|
||||
let st = self.doc_mut()?;
|
||||
if let Some(it) = &mut st.interaction {
|
||||
it.used_defaults_only |= ran_defaults_only;
|
||||
// A failed preview leaves the document at the snapshot, so nothing is left to commit
|
||||
// (not even an earlier successful preview, which the reset above already undid).
|
||||
it.preview = r.is_ok().then(|| (cmd.to_string(), params));
|
||||
@@ -490,6 +493,7 @@ impl Session {
|
||||
// While the Live Paint Bucket is active, a previewed color is the bucket's color, which the
|
||||
// cancel puts back as well, as it does a color previewed with `defaultsOnly: true`.
|
||||
let bucket = self.bucket_paints();
|
||||
let used_defaults_only = self.active().and_then(|st| st.interaction.as_ref()).is_some_and(|it| it.used_defaults_only);
|
||||
if let Some(paint) = self
|
||||
.active()
|
||||
.and_then(|st| st.interaction.as_ref())
|
||||
@@ -511,8 +515,11 @@ impl Session {
|
||||
// A canceled preview's Assign Profile is undone with it.
|
||||
self.sync_front_profiles();
|
||||
// With New Art Has Basic Appearance off, new art takes the appearance of the selection as
|
||||
// the document has it again, not as a preview left it.
|
||||
self.inherit_new_art();
|
||||
// the document has it again, not as a preview left it. An interaction that changed only the
|
||||
// defaults (`defaultsOnly: true`) leaves the defaults it began with.
|
||||
if !used_defaults_only {
|
||||
self.inherit_new_art();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -3468,6 +3468,25 @@ fn live_paint_bucket_commands_replay_from_the_journal_with_another_tool() {
|
||||
s.preview("stroke.set", &json!({"weight": 7})).unwrap();
|
||||
s.cancel_interaction().unwrap();
|
||||
assert_eq!(s.paint.stroke_width, 2.0, "the canceled interaction's weight is not kept");
|
||||
// With New Art Has Basic Appearance off and an object selected, canceling such an interaction
|
||||
// keeps the defaults it began with, not the selection's appearance.
|
||||
let mut s = session();
|
||||
let (_, art, ..) = setup(&mut s, false);
|
||||
s.execute("paint.setFill", &json!({"color": "#ff0000", "defaultsOnly": true})).unwrap();
|
||||
let (red, selected) = (s.paint.fill.clone(), node(&s, art));
|
||||
s.begin_interaction("Fill Color").unwrap();
|
||||
s.preview("paint.setFill", &json!({"color": "#00ffff", "defaultsOnly": true})).unwrap();
|
||||
s.preview("stroke.set", &json!({"weight": 7})).unwrap();
|
||||
s.cancel_interaction().unwrap();
|
||||
assert_eq!((s.paint.fill.clone(), s.paint.stroke_width), (red, 2.0), "the defaults the interaction began with stay");
|
||||
assert_eq!(node(&s, art), selected, "the selection keeps its paint");
|
||||
// The same when the defaults-only step was inside a batch that a later preview replaced.
|
||||
s.begin_interaction("Fill Color").unwrap();
|
||||
let step = json!({"command": "paint.setFill", "params": {"color": "#00ffff", "defaultsOnly": true}});
|
||||
s.preview("command.batch", &json!({"commands": [step]})).unwrap();
|
||||
s.preview("stroke.set", &json!({"weight": 7})).unwrap();
|
||||
s.cancel_interaction().unwrap();
|
||||
assert_eq!(s.paint.fill, Paint::solid(Color::from_hex("#ff0000").unwrap()), "a batch's defaults-only step is put back");
|
||||
// `defaultsOnly` is a bool, and names no objects or brush.
|
||||
let (g, ..) = setup(&mut s, true);
|
||||
for (cmd, params) in [
|
||||
|
||||
Reference in New Issue
Block a user