mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-22 02:15:24 +01:00
Recolor Artwork: another color group or Save Changes leaves Undo Changes no step
Selecting another color group in the Color Groups list, or no group, and Save Changes now clear the dialog's own history. Before, Undo Changes could restore rows read for the previous group, and OK then wrote them to the group now selected; after Save Changes it could restore colors the save had already replaced in the document.
This commit is contained in:
1 parent
1e3a395263
commit
a273744896
5 files changed
+92
-5
No files matched your search
@@ -928,7 +928,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.recolorUndo",
|
||||
"Undo Changes",
|
||||
"",
|
||||
"{} the open Recolor Artwork dialog goes back one of its own color edits (rows, Colors, Method, the Preserve options, Limit to Library, the harmony rule, Global Adjust, the Color Theme Picker's picks, the Prominent Colors weights): its fields and the preview return to their values before that edit; the document's undo history is unchanged, and OK still records one undo step → {changed, canUndo, canRedo}; an error when the dialog isn't open. Each opening starts with nothing to undo",
|
||||
"{} the open Recolor Artwork dialog goes back one of its own color edits (rows, Colors, Method, the Preserve options, Limit to Library, the harmony rule, Global Adjust, the Color Theme Picker's picks, the Prominent Colors weights): its fields and the preview return to their values before that edit; the document's undo history is unchanged, and OK still records one undo step → {changed, canUndo, canRedo}; an error when the dialog isn't open. Each opening starts with nothing to undo, and selecting another color group or Save Changes leaves nothing to undo or redo",
|
||||
),
|
||||
(
|
||||
"ui.recolorRedo",
|
||||
|
||||
@@ -73,7 +73,8 @@
|
||||
//! Undo Changes and Redo Changes beside the Color Theme Picker (`ui.recolorUndo`, `ui.recolorRedo`)
|
||||
//! step back and forward through the dialog's own color edits ([`History`]), not the document's
|
||||
//! undo history; Cancel discards them and OK still records one undo step. Each opening starts
|
||||
//! with nothing to undo.
|
||||
//! with nothing to undo, and selecting another color group or Save Changes leaves nothing to undo
|
||||
//! or redo.
|
||||
//!
|
||||
//! Fields (`ui.dialog.set`): `rows` ([{from: [keys], to: key, exclude?, tint?: percent of a spot
|
||||
//! color, added?}]; a row with no current colors, `from: []`, recolors no art, and with `added: true`
|
||||
@@ -502,6 +503,7 @@ fn select_group(app: &mut VectorcraftApp, d: &mut Dialog) -> Result<(), String>
|
||||
Value::Null => {
|
||||
// No group: without art OK saves the rows as a new color group.
|
||||
d.fields.insert(GROUP_LOADED.into(), Value::Null);
|
||||
restart_history(app);
|
||||
if !art {
|
||||
d.fields.insert("__newGroup".into(), json!(true));
|
||||
d.fields.insert("groupName".into(), json!(NEW_GROUP));
|
||||
@@ -545,6 +547,7 @@ fn select_group(app: &mut VectorcraftApp, d: &mut Dialog) -> Result<(), String>
|
||||
d.fields.remove(COMPS);
|
||||
}
|
||||
d.fields.insert("__assign".into(), Value::Array(assign));
|
||||
restart_history(app);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -566,6 +569,7 @@ fn group_action(app: &mut VectorcraftApp, d: &mut Dialog, action: &Value) -> Res
|
||||
// Nothing changed since the last save but perhaps the name.
|
||||
let name = d.str("groupName");
|
||||
if name.trim().is_empty() || group.as_deref() == Some(name.as_str()) {
|
||||
restart_history(app);
|
||||
return Ok(());
|
||||
}
|
||||
cancel_preview(app, d);
|
||||
@@ -579,6 +583,7 @@ fn group_action(app: &mut VectorcraftApp, d: &mut Dialog, action: &Value) -> Res
|
||||
d.fields.insert("group".into(), name.clone());
|
||||
d.fields.insert(GROUP_LOADED.into(), name.clone());
|
||||
d.fields.insert("groupName".into(), name);
|
||||
restart_history(app);
|
||||
Ok(())
|
||||
}
|
||||
Some("save") => {
|
||||
@@ -685,6 +690,7 @@ fn group_action(app: &mut VectorcraftApp, d: &mut Dialog, action: &Value) -> Res
|
||||
reread_rows(app, d, &rs, &before, &gone);
|
||||
}
|
||||
}
|
||||
restart_history(app);
|
||||
Ok(())
|
||||
}
|
||||
Some("delete") => {
|
||||
@@ -1485,6 +1491,13 @@ pub struct History {
|
||||
redo: Vec<Snapshot>,
|
||||
}
|
||||
|
||||
/// Drop the dialog's steps, after another color group is selected or Save Changes rewrites the
|
||||
/// group: Undo Changes and Redo Changes then have no step to go to, and the next frame or step
|
||||
/// takes the fields as they are then.
|
||||
fn restart_history(app: &mut VectorcraftApp) {
|
||||
app.ui.recolor_history = History::default();
|
||||
}
|
||||
|
||||
/// 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()
|
||||
@@ -3772,6 +3785,79 @@ mod tests {
|
||||
assert_eq!(group_hex(&app, "A"), Some(vec!["#ff0000".into(), "#00ff00".into()]), "other groups are left as they are");
|
||||
}
|
||||
|
||||
/// Without art: selecting another color group in the list and Save Changes leave Undo Changes
|
||||
/// and Redo Changes no step to go to, so OK gives the selected group the rows read for it.
|
||||
#[test]
|
||||
fn another_group_or_save_changes_leaves_nothing_to_undo() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
||||
app.run("swatch.newGroup", json!({"name": "A", "colors": ["#ff0000", "#00ff00"], "keepModel": true})).unwrap();
|
||||
app.run("swatch.newGroup", json!({"name": "B", "colors": ["#0000ff", "#ffff00", "#ffffff"], "keepModel": true})).unwrap();
|
||||
app.run("ui.recolorDialog", json!({"group": "A"})).unwrap();
|
||||
frame(&mut app, &ctx, 0.0, vec![], 0);
|
||||
let edit = |app: &mut VectorcraftApp, to: &str| {
|
||||
let d = app.ui.dialog.as_mut().unwrap();
|
||||
let mut rs = super::rows(d);
|
||||
rs[0]["to"] = json!(to);
|
||||
d.fields.insert("rows".into(), Value::Array(rs));
|
||||
};
|
||||
edit(&mut app, "rgb 0 0 0");
|
||||
frame(&mut app, &ctx, 0.1, vec![], 0);
|
||||
assert!(super::can_step(&app, true), "the edit is a step");
|
||||
|
||||
set(&mut app, "group", json!("B")).unwrap();
|
||||
frame(&mut app, &ctx, 0.2, vec![], 0);
|
||||
assert!(!super::can_step(&app, true) && !super::can_step(&app, false), "another group leaves no step");
|
||||
assert_eq!(super::step(&mut app, true).unwrap()["changed"], json!(false));
|
||||
assert_eq!(new_colors(&app).len(), 3, "the rows of B");
|
||||
|
||||
edit(&mut app, "rgb 0 128 0");
|
||||
frame(&mut app, &ctx, 0.3, vec![], 0);
|
||||
assert!(super::can_step(&app, true), "the edit is a step");
|
||||
act(&mut app, &ctx, 0.4, "save").unwrap();
|
||||
assert_eq!(group_hex(&app, "B"), Some(vec!["#008000".into(), "#ffff00".into(), "#ffffff".into()]));
|
||||
assert!(!super::can_step(&app, true) && !super::can_step(&app, false), "Save Changes leaves no step");
|
||||
assert_eq!(super::step(&mut app, true).unwrap()["changed"], json!(false));
|
||||
|
||||
crate::dialogs::confirm(&mut app).unwrap();
|
||||
assert_eq!(group_hex(&app, "B"), Some(vec!["#008000".into(), "#ffff00".into(), "#ffffff".into()]), "OK keeps B's saved colors");
|
||||
assert_eq!(group_hex(&app, "A"), Some(vec!["#ff0000".into(), "#00ff00".into()]), "and leaves A as it was");
|
||||
}
|
||||
|
||||
/// With art not linked to the group: Save Changes with the rows as the last Save Changes left
|
||||
/// them, after an edit and Undo Changes, leaves Redo Changes no step to go to either.
|
||||
#[test]
|
||||
fn an_unchanged_save_changes_leaves_nothing_to_redo() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
app.run("file.new", json!({"width": 300, "height": 100})).unwrap();
|
||||
let (red, blue) = (square(&mut app, 10.0, "#ff0000"), square(&mut app, 40.0, "#0000ff"));
|
||||
app.run("swatch.newGroup", json!({"name": "Plain", "colors": ["#ff0000", "#0000ff"], "keepModel": true})).unwrap();
|
||||
app.run("select.set", json!({"ids": [red, blue]})).unwrap();
|
||||
app.run("ui.recolorDialog", json!({"group": "Plain"})).unwrap();
|
||||
frame(&mut app, &ctx, 0.0, vec![], 0);
|
||||
let edit = |app: &mut VectorcraftApp, to: &str| {
|
||||
let d = app.ui.dialog.as_mut().unwrap();
|
||||
let mut rs = super::rows(d);
|
||||
rs[0]["to"] = json!(to);
|
||||
d.fields.insert("rows".into(), Value::Array(rs));
|
||||
};
|
||||
edit(&mut app, "rgb 0 128 0");
|
||||
frame(&mut app, &ctx, 0.1, vec![], 0);
|
||||
act(&mut app, &ctx, 0.2, "save").unwrap();
|
||||
assert!(app.ui.dialog.as_ref().unwrap().fields.contains_key(SAVED_ROWS), "the art kept its colors");
|
||||
edit(&mut app, "rgb 0 0 0");
|
||||
frame(&mut app, &ctx, 0.3, vec![], 0);
|
||||
assert_eq!(super::step(&mut app, true).unwrap()["changed"], json!(true));
|
||||
assert!(unchanged_since_save(app.ui.dialog.as_ref().unwrap()), "the rows are as saved");
|
||||
assert!(super::can_step(&app, false), "the edit can be redone");
|
||||
act(&mut app, &ctx, 0.4, "save").unwrap();
|
||||
assert!(!super::can_step(&app, true) && !super::can_step(&app, false), "Save Changes leaves no step");
|
||||
}
|
||||
|
||||
/// Without art: after a group is picked in the list, the same Color Theme Picker picks that gave
|
||||
/// the group before it its colors give the new group's rows the palette of the art picked too.
|
||||
#[test]
|
||||
|
||||
@@ -929,7 +929,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"ui.recolorUndo",
|
||||
"Undo Changes",
|
||||
"",
|
||||
"{} the open Recolor Artwork dialog goes back one of its own color edits (rows, Colors, Method, the Preserve options, Limit to Library, the harmony rule, Global Adjust, the Color Theme Picker's picks, the Prominent Colors weights): its fields and the preview return to their values before that edit; the document's undo history is unchanged, and OK still records one undo step → {changed, canUndo, canRedo}; an error when the dialog isn't open. Each opening starts with nothing to undo",
|
||||
"{} the open Recolor Artwork dialog goes back one of its own color edits (rows, Colors, Method, the Preserve options, Limit to Library, the harmony rule, Global Adjust, the Color Theme Picker's picks, the Prominent Colors weights): its fields and the preview return to their values before that edit; the document's undo history is unchanged, and OK still records one undo step → {changed, canUndo, canRedo}; an error when the dialog isn't open. Each opening starts with nothing to undo, and selecting another color group or Save Changes leaves nothing to undo or redo",
|
||||
),
|
||||
(
|
||||
"ui.recolorRedo",
|
||||
|
||||
+2
-1
@@ -5289,7 +5289,8 @@ 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. Save All Colors and Save Prominent Colors add a color
|
||||
the oldest first. 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. 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.
|
||||
|
||||
The `recolor.*` commands refuse parameters of the wrong form. A `limitTo` or `method` that is not a string gets the
|
||||
|
||||
@@ -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, 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` 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, 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.
|
||||
- **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.
|
||||
|
||||
Reference in new issue
Block a user