mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
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.
This commit is contained in:
1 parent
3919499f10
commit
a36c8ce509
3 files changed
+32
-1
No files matched your search
@@ -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]
|
||||
|
||||
@@ -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<vectorcraft_tools::PaintDefaults>,
|
||||
/// 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<vectorcraft_tools::PaintDefaults>,
|
||||
/// Conversion of new-art paints waits until a color-mode preview is accepted.
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in new issue
Block a user