From 585fd878fa0cc37e7d3abdf8366756d771c230c1 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 16:23:48 -0800 Subject: [PATCH] Recolor Artwork: Undo Changes keeps its newest step past the byte limit The dialog's history always keeps the step to the current fields, so Undo Changes is never enabled with no step to go to. --- crates/ui-egui/src/dialogs/recolor.rs | 33 ++++++++++++++++----------- docs/mcp.md | 2 +- docs/target-app-parity.md | 2 +- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/crates/ui-egui/src/dialogs/recolor.rs b/crates/ui-egui/src/dialogs/recolor.rs index fb2dc8453c..10b0cb425e 100644 --- a/crates/ui-egui/src/dialogs/recolor.rs +++ b/crates/ui-egui/src/dialogs/recolor.rs @@ -1500,6 +1500,11 @@ fn restart_history(app: &mut VectorcraftApp, d: &Dialog) { app.ui.recolor_history = History { opened: Some(snapshot(d)), ..History::default() }; } +/// The size of `s` as JSON, which [`MAX_STEP_BYTES`] limits. +fn snapshot_size(s: &Snapshot) -> usize { + serde_json::to_vec(s).map_or(0, |b| b.len()) +} + /// The fields of `d` a step restores ([`STEP_FIELDS`] and [`STEP_MARKS`]). fn snapshot(d: &Dialog) -> Snapshot { STEP_FIELDS.iter().chain(&STEP_MARKS).filter_map(|k| Some((k.to_string(), d.fields.get(*k)?.clone()))).collect() @@ -1551,16 +1556,15 @@ impl History { } } - /// Drop the oldest steps past [`MAX_STEPS`] and [`MAX_STEP_BYTES`] (all of them when the - /// current fields alone pass it). + /// Drop the oldest steps past [`MAX_STEPS`] and [`MAX_STEP_BYTES`], keeping the newest step + /// even when it and the current fields alone pass the byte limit. fn trim(&mut self) { let extra = self.undo.len().saturating_sub(MAX_STEPS); self.undo.drain(..extra); - let size = |s: &Snapshot| serde_json::to_vec(s).map_or(0, |b| b.len()); - let mut total: usize = self.base.iter().chain(&self.undo).map(size).sum(); + let mut total: usize = self.base.iter().chain(&self.undo).map(snapshot_size).sum(); let mut gone = 0; - while total > MAX_STEP_BYTES && gone < self.undo.len() { - total -= size(&self.undo[gone]); + while total > MAX_STEP_BYTES && gone + 1 < self.undo.len() { + total -= snapshot_size(&self.undo[gone]); gone += 1; } self.undo.drain(..gone); @@ -3663,8 +3667,8 @@ mod tests { } /// Undo Changes keeps at most [`MAX_STEPS`] steps and [`MAX_STEP_BYTES`] of them, the oldest - /// going first; fields that change nothing make no step, and fields larger than the limit - /// leave nothing to undo. + /// going first; fields that change nothing make no step, and with fields larger than the limit + /// only the newest step is kept, so Undo Changes is never on with no step to go to. #[test] fn undo_changes_keeps_a_bounded_history() { let mut d = Dialog::new(KIND, json!({"rows": [], "colors": null})); @@ -3690,14 +3694,17 @@ mod tests { assert!(h.undo.len() < 60 && !h.undo.is_empty(), "{}", h.undo.len()); assert!(h.step(&mut d, true), "the newest step is kept"); assert_eq!(d.fields["rows"], big(58)); - // Current fields past the limit alone: nothing is left to undo before them. + // Current fields past the limit alone: only the step to them is kept, so Undo Changes + // still goes back one step. d.fields.insert("rows".into(), json!([{"from": ["x".repeat(MAX_STEP_BYTES)], "to": null}])); h.note(&d); - assert!(h.undo.is_empty() && h.redo.is_empty()); - assert!(!h.can(&d, true)); + assert!(h.undo.len() == 1 && h.redo.is_empty(), "{}", h.undo.len()); d.fields.insert("colors".into(), json!(1)); - assert!(!h.step(&mut d, true), "a step of them is not kept either"); - assert_eq!(d.fields["colors"], json!(1), "and the fields stay as they are"); + assert!(h.can(&d, true), "the change to colors is a step too"); + assert!(h.step(&mut d, true), "and it is kept"); + assert_eq!(d.fields["colors"], json!(MAX_STEPS + 5), "Undo Changes gives back the colors before it"); + assert_eq!(h.undo.len(), 0, "the step before it went to keep the newest"); + assert!(!h.can(&d, true)); } /// Sets `field` of the open dialog to `value` as `ui.dialog.set` does: a refused value leaves diff --git a/docs/mcp.md b/docs/mcp.md index c264022a92..5086959b8b 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -5289,7 +5289,7 @@ with `ui.dialog.set` become a step at the dialog's next frame with the pointer u down. Reset is a step of its own, which Undo Changes reverses. A new edit after Undo Changes leaves nothing to redo. Switching tabs, displays or slider modes, selecting rows, Find and Preview make no step. The dialog keeps at most 64 steps and 4 MiB of them as JSON, dropping -the oldest first. A button with no step to go to is disabled. Selecting another color group (or no group) and Save +the oldest first, and always keeps the newest step. A button with no step to go to is disabled. Selecting another color group (or no group) and Save Changes leave nothing to undo or redo, and an edit after either is a step back to the fields as they were then. Save All Colors and Save Prominent Colors add a color group to the document at once, as its own undo step, and Cancel and Undo Changes leave that group in place. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index dc39142f4f..09ab56cb9b 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1903,7 +1903,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Recolor Artwork Find:** the Assign tab's Find button finds the colors of the selected rows in the art ([Advanced recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/learn-color-basics/edit-colors-dialog-overview.html)): while it is on, their art shows as the preview shows it and the rest of the selected art shows dimmed, until a second click ([archived help, Recolor Artwork](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=149)). VectorCraft's own rules: a dimmed color is a 25% tint of its current color (or the nearest lighter tint when that one is a color a selected row lists), a color a selected row also lists is not dimmed, and Find records no undo step. `findColors` is the dialog field. Tests: `find_dims_the_colors_of_the_rows_not_selected` and `find_shows_the_selected_rows_art_and_dims_the_rest` in `crates/ui-egui/src/dialogs/recolor.rs`. Scores and estimates unchanged. - **Recolor Artwork color groups list:** a list on the right of the dialog shows the document's color groups, and the Show Color Groups button beside the tabs shows or hides it. A click on a group makes it the group being edited, and the rows take its colors. Save Changes rewrites the selected group with the new colors, New Color Group saves them as a new group, and Delete removes the selected group; the Swatches panel shows each change ([Advanced recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/learn-color-basics/edit-colors-dialog-overview.html)). VectorCraft's own rules: when the art has colors of the group, Save Changes and OK keep the group's swatches in order, and a swatch no row lists keeps its color; an excluded row leaves its swatch its own color; after a save with art, the rows' new colors take the Global Adjust, which goes back to 0%. `group`, `groupStorage` and `groupAction` are the dialog fields. Tests: `the_color_groups_list_selects_saves_and_deletes_groups`, `a_group_picked_in_the_list_recolors_the_art` and the `saving_a_group_` tests in `crates/ui-egui/src/dialogs/recolor.rs`, and `edit_color_group_with_its_own_colors_records_no_undo_step` and `edit_color_group_with_its_own_color_keys_keeps_the_colors` in `crates/engine/src/tests/swatchcmds.rs`. - **Recolor Artwork New Row:** the Assign tab's New Row button adds a row with no current colors, so current colors can be moved into it and take its new color ([Advanced recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/learn-color-basics/edit-colors-dialog-overview.html), [Assign new colors to selected artworks](https://helpx.adobe.com/illustrator/desktop/manage-colors/modify-colors/assign-new-colors-to-selected-artwork.html)). VectorCraft's own rules: the row goes above the first selected row (at the top when none is selected) with that row's new color and becomes the selection, and Merge with it as the first selected row moves the other rows' colors into it. The button needs selected art. An empty row recolors nothing, does not count toward Colors, adds no library swatch and gives a rewritten color group no color. While it is empty, Save All Colors and a new color group saved from colors alone leave its new color out, the Edit tab's wheel, bars and chips do not show it and its sliders edit the base color instead, the harmony rules and linked moves leave its new color as it is, and the Color Theme Picker gives it no color. Tests: `a_new_row_goes_above_the_selection_and_takes_merged_colors`, `an_empty_row_gives_the_group_no_color`, `an_empty_row_gives_a_new_group_no_color`, `an_empty_row_takes_no_harmony_or_wheel_color`, `theme_picks_leave_an_empty_row_out`, `save_all_colors_leaves_an_empty_row_out` and `colors_merged_into_a_new_row_take_its_new_color` in `crates/ui-egui/src/dialogs/recolor.rs`, `an_empty_row_recolors_nothing` and `an_empty_row_adds_no_swatch_and_no_group_color` in `crates/engine/src/tests/recolor.rs`. - - **Recolor Artwork Undo Changes and Redo Changes:** two buttons beside the Color Theme Picker go back and forward one color edit made in the open dialog, and Undo Changes has nothing to undo after the dialog is opened again ([Recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/modify-colors/recolor-options-overview.html)); `ui.recolorUndo` and `ui.recolorRedo` run them. VectorCraft's own rules: the dialog's history is separate from the document's, which changes when OK records one undo step and when Save All Colors or Save Prominent Colors adds a color group at once as its own undo step, which Cancel and Undo Changes leave in place; a drag is one step, fields set with `ui.dialog.set` before the next frame with the pointer up or the next step are one step, Reset is a step of its own, a new edit leaves nothing to redo, selecting another color group or Save Changes leaves nothing to undo or redo, a button with no step to go to is disabled, and the dialog keeps at most 64 steps and 4 MiB of them. Tests: `undo_and_redo_changes_step_through_the_dialogs_own_edits`, `a_drag_is_one_step_of_undo_changes`, `undo_changes_reverses_reset`, `the_recolor_undo_and_redo_commands_step_the_open_dialog`, `the_recolor_undo_and_redo_commands_preview_the_step`, `an_edit_with_the_pointer_down_from_the_first_frame_is_a_step` and `rows_and_weights_set_before_the_art_is_read_are_no_step` in `crates/ui-egui/src/tests/recolor.rs`, and `undo_changes_keeps_a_bounded_history` and `another_group_or_save_changes_leaves_nothing_to_undo` and `an_unchanged_save_changes_leaves_nothing_to_redo` in `crates/ui-egui/src/dialogs/recolor.rs`. Scores and estimates unchanged. + - **Recolor Artwork Undo Changes and Redo Changes:** two buttons beside the Color Theme Picker go back and forward one color edit made in the open dialog, and Undo Changes has nothing to undo after the dialog is opened again ([Recolor options overview](https://helpx.adobe.com/illustrator/desktop/manage-colors/modify-colors/recolor-options-overview.html)); `ui.recolorUndo` and `ui.recolorRedo` run them. VectorCraft's own rules: the dialog's history is separate from the document's, which changes when OK records one undo step and when Save All Colors or Save Prominent Colors adds a color group at once as its own undo step, which Cancel and Undo Changes leave in place; a drag is one step, fields set with `ui.dialog.set` before the next frame with the pointer up or the next step are one step, Reset is a step of its own, a new edit leaves nothing to redo, selecting another color group or Save Changes leaves nothing to undo or redo and an edit after either is a step back to the fields as they were then, a button with no step to go to is disabled, and the dialog keeps at most 64 steps and 4 MiB of them, always keeping the newest step. Tests: `undo_and_redo_changes_step_through_the_dialogs_own_edits`, `a_drag_is_one_step_of_undo_changes`, `undo_changes_reverses_reset`, `the_recolor_undo_and_redo_commands_step_the_open_dialog`, `the_recolor_undo_and_redo_commands_preview_the_step`, `an_edit_with_the_pointer_down_from_the_first_frame_is_a_step` and `rows_and_weights_set_before_the_art_is_read_are_no_step` in `crates/ui-egui/src/tests/recolor.rs`, and `undo_changes_keeps_a_bounded_history` and `another_group_or_save_changes_leaves_nothing_to_undo` and `an_edit_right_after_another_group_is_a_step` and `an_unchanged_save_changes_leaves_nothing_to_redo` in `crates/ui-egui/src/dialogs/recolor.rs`. Scores and estimates unchanged. - **Edit Colors parameters:** `edit.colors.saturate` needs a number `intensity`, the value from -100% to 100% that Saturate takes ([Adjusting colors](https://web.archive.org/web/20230128232631/https://helpx.adobe.com/illustrator/using/adjusting-colors.html)), and answers "missing number `intensity`" without one; a number outside the range counts as its nearest end. A value that is not a number, such as `"40"`, is refused with `` `intensity` must be a number, not "40" ``, as in every command that needs a number (`tests::params::a_malformed_required_number_is_not_reported_as_missing`). `edit.colors.adjustBalance` refuses a channel and `color.harmony` refuses `steps` or `amount` that is not a number; both read `null` as a value left out. `tests::editcolors` and `tests::colorguide` cover them. - **Convert to Indexed Color:** Edit › Edit Colors › Convert to Indexed Color… (`edit.colors.toIndexed`) stores the embedded images in the selection as indexed-color PNGs of at most 256 colors. The palette is chosen as for a PNG-8 export, as evenly spaced levels of red, green and blue, or from the document's swatches, with diffusion, pattern or noise dithering; pixels under half opacity become transparent. The dialog previews live, and OK is one undo step. This is VectorCraft's own command and counts toward no score. `tests::editcolors` and `encode::tests_palette` cover it. Scores and estimates unchanged. - **Working RGB numeric controls:** the Color panel and Color Picker read RGB, HSB, hex and Web Safe RGB values in the active working RGB space. Editing one RGB channel preserves the other native channels, including colors outside display sRGB. Regressions cover sRGB, Display P3, Wide Gamut RGB and ProPhoto RGB, picker initialization, native numeric round trips, and a slider click with one Undo step. Scores and estimates unchanged.