mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 18:32:23 +00:00
Live Paint: canceling restores the defaults after a later ordinary preview
An interaction that previewed a command with defaultsOnly: true keeps putting the defaults it began with back on every later preview and on cancel, also when the latest preview gives no defaultsOnly. docs/mcp.md says that library.use keeps item as the library item.
This commit is contained in:
@@ -10,6 +10,9 @@ pub struct Interaction {
|
||||
pub preview: Option<(String, Value)>,
|
||||
/// A replaced or canceled preview restores these new-art paints from before the interaction.
|
||||
pub(crate) paint: vectorcraft_tools::PaintDefaults,
|
||||
/// A preview of the interaction gave `defaultsOnly: true`: every later preview and a cancel put
|
||||
/// `paint` back, whichever preview is the latest.
|
||||
pub(crate) used_defaults_only: bool,
|
||||
/// An accepted batch preview uses these final paints after changing the document color mode.
|
||||
pub(crate) preview_paint: Option<vectorcraft_tools::PaintDefaults>,
|
||||
/// Conversion of new-art paints waits until a color-mode preview is accepted.
|
||||
|
||||
@@ -301,6 +301,7 @@ impl Session {
|
||||
selection: Arc::new(st.selection.clone()),
|
||||
preview: None,
|
||||
paint,
|
||||
used_defaults_only: false,
|
||||
preview_paint: None,
|
||||
color_mode_paints: None,
|
||||
deferred_color_mode: None,
|
||||
@@ -338,9 +339,10 @@ impl Session {
|
||||
st.doc = it.doc.clone();
|
||||
// A batch, or a preview that changed the new-art paints (a pattern rename), started from
|
||||
// the paints the interaction began with.
|
||||
it.used_defaults_only |= cmd::asks_defaults_only(params);
|
||||
let restore_paint = bucket
|
||||
|| cmd == "command.batch"
|
||||
|| cmd::asks_defaults_only(params)
|
||||
|| it.used_defaults_only
|
||||
|| it.preview.as_ref().is_some_and(|(id, p)| id == "command.batch" || cmd::asks_defaults_only(p))
|
||||
|| it.color_mode_paints.is_some();
|
||||
let paint = it.paint.clone();
|
||||
@@ -493,6 +495,7 @@ impl Session {
|
||||
.and_then(|st| st.interaction.as_ref())
|
||||
.filter(|it| {
|
||||
bucket
|
||||
|| it.used_defaults_only
|
||||
|| it.preview.as_ref().is_some_and(|(id, p)| id == "command.batch" || cmd::asks_defaults_only(p))
|
||||
|| it.color_mode_paints.is_some()
|
||||
})
|
||||
|
||||
@@ -3461,9 +3461,21 @@ fn live_paint_bucket_commands_replay_from_the_journal_with_another_tool() {
|
||||
s.cancel_interaction().unwrap();
|
||||
assert_eq!((s.paint.fill.clone(), s.paint.stroke_width), (fill.clone(), 2.0));
|
||||
assert_eq!((node(&s, g), node(&s, art)), (group, painted), "the selection keeps its paint");
|
||||
// A later preview without `defaultsOnly` leaves the interaction one that changed the defaults:
|
||||
// canceling puts them back.
|
||||
s.begin_interaction("Stroke Weight").unwrap();
|
||||
s.preview("stroke.weightUp", &json!({"defaultsOnly": true})).unwrap();
|
||||
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");
|
||||
// `defaultsOnly` is a bool, and names no objects or brush.
|
||||
let (g, ..) = setup(&mut s, true);
|
||||
for (cmd, params) in [
|
||||
("paint.none", json!({"defaultsOnly": true, "ids": [g.0]})),
|
||||
("paint.none", json!({"defaultsOnly": true, "id": g.0})),
|
||||
("paint.none", json!({"defaultsOnly": true, "item": null})),
|
||||
("paint.sampleColor", json!({"color": "#00ffff", "defaultsOnly": true, "id": g.0})),
|
||||
("paint.sampleColor", json!({"color": "#00ffff", "defaultsOnly": true, "item": null})),
|
||||
("paint.setFill", json!({"color": "#00ffff", "defaultsOnly": "yes"})),
|
||||
("paint.setFill", json!({"color": "#00ffff", "defaultsOnly": true, "ids": [g.0]})),
|
||||
("stroke.set", json!({"weight": 3, "defaultsOnly": true, "item": 0})),
|
||||
|
||||
+3
-3
@@ -4842,10 +4842,10 @@ already walks Image Trace. Short agent entry points:
|
||||
paint, and no undo step is recorded. A null `ids` or `id` counts as left out. The journal records each of these
|
||||
commands with `defaultsOnly: true`, and it records `library.use` with a color, gradient or pattern and
|
||||
`swatch.library.add` with `apply` the same way. A replay of the entry, or the same params sent with any tool active, changes
|
||||
only the defaults. `defaultsOnly` is a bool, and it is refused together with `ids`, `id` or `item`, and in
|
||||
`stroke.setAdvanced` together with `brush`. While the bucket is active, `defaultsOnly: false` without a target is
|
||||
only the defaults. `defaultsOnly` is a bool, and it is refused together with `ids`, `id` or an appearance `item` (`library.use` takes
|
||||
`item` as the library item to apply, which stays valid), and in `stroke.setAdvanced` together with `brush`. While the bucket is active, `defaultsOnly: false` without a target is
|
||||
journaled as `true`. A preview with `defaultsOnly: true` starts from the defaults the interaction began with, and
|
||||
canceling the interaction puts them back. The Stroke panel's other options
|
||||
canceling the interaction puts them back, also after a later preview without `defaultsOnly`. The Stroke panel's other options
|
||||
(`stroke.set`, `stroke.setAdvanced` without `brush`) change the stroke for new art and leave the selection as it is;
|
||||
the bucket takes only the color and weight of that stroke. A stop selected on the bucket's gradient
|
||||
(`gradient.selectStop`) is deselected when another tool is chosen, when the first selected object changes, when an
|
||||
|
||||
Reference in New Issue
Block a user