From a01bf5e0adb6ef194a4e44f9b2f024496e515079 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 15:21:21 -0800 Subject: [PATCH] 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. --- crates/ui-egui/src/dialogs/recolor.rs | 8 ++++++++ crates/ui-egui/src/tests/recolor.rs | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/crates/ui-egui/src/dialogs/recolor.rs b/crates/ui-egui/src/dialogs/recolor.rs index 7122387916..e5febf0b6c 100644 --- a/crates/ui-egui/src/dialogs/recolor.rs +++ b/crates/ui-egui/src/dialogs/recolor.rs @@ -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) } } diff --git a/crates/ui-egui/src/tests/recolor.rs b/crates/ui-egui/src/tests/recolor.rs index 601fddf712..3c87fd0c71 100644 --- a/crates/ui-egui/src/tests/recolor.rs +++ b/crates/ui-egui/src/tests/recolor.rs @@ -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"); +}