From a36c8ce509cb7bb83d0a5bf609d78fa8bb40d88b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 30 Nov 2026 08:29:17 -0800 Subject: [PATCH] Document Tools: cancel keeps the starting paints after a deselect and a failed preview A preview that started from the paints saved before an earlier preview took the selection's appearance cleared that snapshot. When a later preview then failed, neither the cancel nor the commit after it saw that the new-art paints had changed, and the previewed fill stayed. The interaction now records that such a preview ran, and the cancel and the commit after a failed preview put back the paints it began with. --- .../engine/src/cmd/addons/document/tests.rs | 23 +++++++++++++++++++ crates/engine/src/interaction.rs | 3 +++ crates/engine/src/session/edit.rs | 7 +++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/addons/document/tests.rs b/crates/engine/src/cmd/addons/document/tests.rs index 3114142ba8..4e133eacef 100644 --- a/crates/engine/src/cmd/addons/document/tests.rs +++ b/crates/engine/src/cmd/addons/document/tests.rs @@ -687,6 +687,29 @@ fn cancel_or_commit_after_a_failed_rectangle_preview_restores_the_starting_fill( } } +/// A cancel or a commit puts back the fill the interaction began with when a deselect preview +/// started from the rectangle preview's paints and a failed rectangle preview followed it. +#[test] +fn cancel_or_commit_after_a_deselect_and_a_failed_rectangle_preview_restores_the_starting_fill() { + for commit in [false, true] { + let mut s = boards(); + s.prefs.new_art_basic = false; + s.execute("select.none", &json!({})).unwrap(); + let before = s.paint.clone(); + s.begin_interaction("Rectangle").unwrap(); + s.preview("paint.setFill", &json!({"color": "#0000ff"})).unwrap(); + s.preview("shape.rectangle", &json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); + s.preview("select.none", &json!({})).unwrap(); + assert!(s.preview("shape.rectangle", &json!({"x": 10, "y": 10, "width": "wide", "height": 20})).is_err()); + if commit { + s.commit_interaction().unwrap(); + } else { + s.cancel_interaction().unwrap(); + } + assert_eq!(s.paint, before, "commit {commit}"); + } +} + /// A failed fill preview after a fill preview and a rectangle preview leaves the starting fill for /// the next rectangle preview. #[test] diff --git a/crates/engine/src/interaction.rs b/crates/engine/src/interaction.rs index d3b39bf831..ce3648a59c 100644 --- a/crates/engine/src/interaction.rs +++ b/crates/engine/src/interaction.rs @@ -26,6 +26,9 @@ pub struct Interaction { /// The preview inherited new-art paints from a selection absent at interaction start: the /// new-art paints from before that, which the next preview starts from. pub(crate) inherited_preview_paint: Option, + /// A successful preview started from `inherited_preview_paint`: the new-art paints changed + /// during the interaction, so a cancel, or a commit after a failed preview, puts `paint` back. + pub(crate) inherited_preview_paint_used: bool, /// An accepted batch preview uses these final paints after changing the document color mode. pub(crate) preview_paint: Option, /// Conversion of new-art paints waits until a color-mode preview is accepted. diff --git a/crates/engine/src/session/edit.rs b/crates/engine/src/session/edit.rs index 5195b2df14..a9794438bd 100644 --- a/crates/engine/src/session/edit.rs +++ b/crates/engine/src/session/edit.rs @@ -553,6 +553,7 @@ impl Session { used_defaults_only: false, preserve_paint_on_cancel: false, inherited_preview_paint: None, + inherited_preview_paint_used: false, preview_paint: None, color_mode_paints: None, tool_paints: false, @@ -660,6 +661,9 @@ impl Session { if r.is_err() && !restore_paint && it.inherited_preview_paint.is_none() { it.inherited_preview_paint.clone_from(&inherited); } + if r.is_ok() && !restore_paint && inherited.is_some() { + it.inherited_preview_paint_used = true; + } if it.color_mode_paints.is_some() { it.preview_paint = batch_paint.clone(); } @@ -692,7 +696,7 @@ impl Session { if let Some(paint) = self .active() .and_then(|st| st.interaction.as_ref()) - .filter(|it| it.preview.is_none() && it.inherited_preview_paint.is_some()) + .filter(|it| it.preview.is_none() && (it.inherited_preview_paint.is_some() || it.inherited_preview_paint_used)) .map(|it| it.paint.clone()) { self.paint = paint; @@ -807,6 +811,7 @@ impl Session { || it.preview.as_ref().is_some_and(|(id, p)| id == "command.batch" || cmd::asks_defaults_only(p)) || it.color_mode_paints.is_some() || it.inherited_preview_paint.is_some() + || it.inherited_preview_paint_used || (!self.prefs.new_art_basic && it.preview.is_some() && it.selection.is_empty()) }) .map(|it| it.paint.clone())