Recolor Artwork: Undo Changes is available after a field is set before the first frame

ui.recolorUndo already went back to the fields the dialog opened with
when ui.dialog.set changed one before the dialog's first frame, but the
command list reported Undo Changes as unavailable. The availability
check now compares the fields with those the dialog opened with until
the first frame or step. Rows that the art's reduction is about to
replace do not count, so the check matches what ui.recolorUndo does.
This commit is contained in:
dotCooCoo
2026-11-17 15:21:21 -08:00
parent c894fd6a2d
commit a01bf5e0ad
2 changed files with 23 additions and 0 deletions
+8
View File
@@ -946,6 +946,14 @@ impl History {
}
fn can(&self, d: &Dialog, back: bool) -> bool {
// Before the first frame or command, fields set since the dialog opened are a step back,
// except rows that the art's reduction is about to replace.
if self.base.is_none()
&& let Some(opened) = &self.opened
{
let reduces = d.bool("__art") && d.fields.get("__reduced") != Some(&reduce_params(d));
return back && STEP_FIELDS.iter().filter(|k| !(reduces && **k == "rows")).any(|k| d.fields.get(*k) != opened.get(*k));
}
if back { !self.undo.is_empty() || self.pending(d) } else { !self.redo.is_empty() && !self.pending(d) }
}
+15
View File
@@ -1704,6 +1704,7 @@ fn the_recolor_undo_and_redo_commands_step_the_open_dialog() {
// A field set before the dialog's first frame is a step back to the fields it opened with.
app.run("ui.recolorDialog", json!({})).unwrap();
set(&mut app, "colors", json!(2));
assert!(dialogs::recolor::can_step(&app, true) && !dialogs::recolor::can_step(&app, false), "Undo Changes can run before the first frame");
let r = app.run("ui.recolorUndo", json!({})).unwrap();
assert_eq!(r, json!({"changed": true, "canUndo": false, "canRedo": true}));
assert_eq!(field(&app, "colors"), Value::Null);
@@ -1764,3 +1765,17 @@ fn an_edit_with_the_pointer_down_from_the_first_frame_is_a_step() {
assert_eq!(r, json!({"changed": true, "canUndo": false, "canRedo": true}));
assert_eq!((field(&app, "colors"), field(&app, "rows")), (Value::Null, start));
}
/// Rows set before the first frame, which the art's reduction then replaces, are no step: Undo
/// Changes is not available and changes nothing.
#[test]
fn rows_set_before_the_art_is_read_are_no_step() {
let mut app = app();
art(&mut app, &["#ff0000", "#0000ff"]);
app.run("ui.recolorDialog", json!({})).unwrap();
set(&mut app, "rows", json!([{"to": "#123456"}]));
assert!(!dialogs::recolor::can_step(&app, true), "Undo Changes is not available");
let r = app.run("ui.recolorUndo", json!({})).unwrap();
assert_eq!(r, json!({"changed": false, "canUndo": false, "canRedo": false}));
assert_eq!(field(&app, "rows").as_array().unwrap().len(), 2, "the rows of the art");
}