mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Merge pull request #9914 from dotCooCoo/fix/move-anchors-no-op-undo
Undo: a move by 0 and Layer Options that change nothing add no step
This commit is contained in:
6 files changed
+78
-5
No files matched your search
@@ -84,7 +84,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Layer Options…",
|
||||
["Window", "Layers"],
|
||||
None,
|
||||
"{ids?|id? (default: the highlighted rows, else the current layer), name? (with prefs.identifyObjectsBy xmlId: a valid XML ID, stored as the object name), visible?, locked?, template?, printable?, preview?, dimImages?: 0..100|false, color?: index 0..26|\"#rrggbb\"|preset name (a hex color with an alpha part, #rrggbbaa or #rgba, is an error)} Layer Options; rows that are not layers take name, visible and locked, and `ids` may name ruler guides (their `guide.list` id), which hide or lock on their own. Template on also locks the layer and dims its images to 50% (unless given); off unlocks it and stops dimming. A path directly in a Live Paint group can't take the name Face or Edge, which name the group's faces and edges, unless it has it already. One undo step",
|
||||
"{ids?|id? (default: the highlighted rows, else the current layer), name? (with prefs.identifyObjectsBy xmlId: a valid XML ID, stored as the object name), visible?, locked?, template?, printable?, preview?, dimImages?: 0..100|false, color?: index 0..26|\"#rrggbb\"|preset name (a hex color with an alpha part, #rrggbbaa or #rgba, is an error)} Layer Options; rows that are not layers take name, visible and locked, and `ids` may name ruler guides (their `guide.list` id), which hide or lock on their own. Template on also locks the layer and dims its images to 50% (unless given); off unlocks it and stops dimming. A path directly in a Live Paint group can't take the name Face or Edge, which name the group's faces and edges, unless it has it already. One undo step, and none when every row already has every option given",
|
||||
has_doc,
|
||||
set_props
|
||||
),
|
||||
@@ -400,6 +400,18 @@ fn apply_options(n: &mut Node, p: &Value, xml_id: bool) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether Layer Options `p` ([`apply_options`]) would change row `n`: its name, eye, lock or
|
||||
/// layer options.
|
||||
fn changes_options(n: &Node, p: &Value, xml_id: bool) -> bool {
|
||||
let mut after = n.clone();
|
||||
apply_options(&mut after, p, xml_id);
|
||||
let options = |n: &Node| match &n.kind {
|
||||
NodeKind::Layer { color, template, printable, preview, dim_images, .. } => Some((*color, *template, *printable, *preview, *dim_images)),
|
||||
_ => None,
|
||||
};
|
||||
after.name != n.name || after.visible != n.visible || after.locked != n.locked || options(&after) != options(n)
|
||||
}
|
||||
|
||||
/// Bad values in Layer Options params, as an error for `cmd`.
|
||||
/// `xml_id`: Preferences › Units › Identify Objects By › XML ID — a non-empty `name` must be a
|
||||
/// valid XML id.
|
||||
@@ -706,6 +718,17 @@ fn set_props(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let name = if xml_id { vectorcraft_doc::xml_id::to_object_name(v) } else { v.to_string() };
|
||||
super::buildcmds::check_part_name(&s.doc()?.doc, &ids, &name)?;
|
||||
}
|
||||
// When every row already has every option given, the document and its undo history stay as
|
||||
// they are.
|
||||
let d = &s.doc()?.doc;
|
||||
if ids.iter().all(|id| d.node(*id).is_some_and(|n| !changes_options(n, p, xml_id))) {
|
||||
// Hidden or locked rows' art can't stay selected.
|
||||
let flag = |k: &str| p.get(k).and_then(Value::as_bool);
|
||||
if flag("visible") == Some(false) || flag("locked") == Some(true) || flag("template") == Some(true) {
|
||||
s.select(|d, sel| sel.deselect_uneditable(d))?;
|
||||
}
|
||||
return ok();
|
||||
}
|
||||
s.edit("Layer Options", |d, sel| {
|
||||
for id in &ids {
|
||||
apply_options(d.node_mut(*id).ok_or(EngineError::NoNode(*id))?, p, xml_id);
|
||||
|
||||
@@ -41,7 +41,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Move Anchors",
|
||||
[],
|
||||
None,
|
||||
"{dx, dy, patterns?: bool (Transform Patterns: pattern fills and strokes transform with the objects that move whole; default: prefs transformPatternTiles), interpolate?: bool (Interpolate Control Points: the handles of each segment with one moved end are re-mapped by the turn, scale and move that take its old ends to its new ends; default: prefs interpolateControlPoints)} move direct-selected anchors (whole paths if fully selected); refused while an object of a symbol instance's art is selected",
|
||||
"{dx, dy (a move by 0 changes nothing and records no undo step), patterns?: bool (Transform Patterns: pattern fills and strokes transform with the objects that move whole; default: prefs transformPatternTiles), interpolate?: bool (Interpolate Control Points: the handles of each segment with one moved end are re-mapped by the turn, scale and move that take its old ends to its new ends; default: prefs interpolateControlPoints)} move direct-selected anchors (whole paths if fully selected); refused while an object of a symbol instance's art is selected",
|
||||
has_selection,
|
||||
move_anchors
|
||||
),
|
||||
@@ -271,6 +271,10 @@ fn move_selected(s: &mut Session, p: &Value, bend: bool) -> Result<Value> {
|
||||
check_switches(p, &["patterns", "interpolate"], C)?;
|
||||
// An object selected in a symbol instance's art stays where the symbol puts it.
|
||||
super::edit::refuse_symbol_part(s)?;
|
||||
// A move by 0 changes nothing, and the document and its undo history stay as they are.
|
||||
if d == Vec2::ZERO {
|
||||
return ok();
|
||||
}
|
||||
let st = s.doc()?;
|
||||
let mut sel = st.selection.clone();
|
||||
let (held, bends) = if bend { held_segments(&st.doc, &mut sel, d) } else { (false, vec![]) };
|
||||
|
||||
@@ -4045,6 +4045,24 @@ fn move_anchors_reshape_and_close_refuse_a_number_given_as_text() {
|
||||
assert!(after.subpaths[0].closed && moved == Some(before.subpaths[0].anchors[1].p.x + 10.0), "{after:?}");
|
||||
}
|
||||
|
||||
/// Move Anchors by 0, with anchors or whole paths selected, changes nothing and records no undo
|
||||
/// step; a move by 10 records one.
|
||||
#[test]
|
||||
fn move_anchors_by_zero_records_no_undo_step() {
|
||||
let mut s = session();
|
||||
let id = curve(&mut s);
|
||||
for select in [json!({"id": id.0, "anchors": [[0, 1]]}), json!({"id": id.0, "anchors": [[0, 0], [0, 1]]})] {
|
||||
s.execute("select.anchors", &select).unwrap();
|
||||
let (before, undo) = (path(&s, id), s.doc().unwrap().history.undo.len());
|
||||
for p in [json!({}), json!({"dx": 0, "dy": 0}), json!({"dx": null, "dy": -0.0})] {
|
||||
s.execute("path.moveAnchors", &p).unwrap();
|
||||
assert_eq!((path(&s, id), s.doc().unwrap().history.undo.len()), (before.clone(), undo), "{select} {p}");
|
||||
}
|
||||
s.execute("path.moveAnchors", &json!({"dx": 10})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1, "{select}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Close Path, Set Handle, Move Anchors and the Pencil, Curvature, Reshape Segment and Blob Brush
|
||||
/// commands refuse an on/off option given as text or as another value that is not true or false,
|
||||
/// naming the key, and change nothing; true, false and null still work.
|
||||
|
||||
@@ -734,6 +734,34 @@ fn object_set_props_that_changes_nothing_deselects_what_it_leaves_hidden_or_lock
|
||||
}
|
||||
}
|
||||
|
||||
/// Layer Options that leave every row as it is change nothing and record no undo step; one that
|
||||
/// changes a row records one.
|
||||
#[test]
|
||||
fn layer_options_that_change_nothing_record_no_undo_step() {
|
||||
let mut s = session();
|
||||
let (layer, sub, a, ..) = tree(&mut s);
|
||||
run(&mut s, "layer.setProps", json!({"id": sub.0, "name": "Sub", "color": "red"}));
|
||||
let before = (s.doc().unwrap().doc.clone(), undos(&s));
|
||||
for p in [
|
||||
json!({}),
|
||||
json!({"id": layer.0, "visible": true, "locked": false, "template": false, "printable": true, "preview": true, "dimImages": false}),
|
||||
json!({"id": sub.0, "name": "Sub", "color": "red"}),
|
||||
json!({"id": sub.0, "name": " "}),
|
||||
json!({"ids": [a.0, sub.0], "visible": true}),
|
||||
] {
|
||||
run(&mut s, "layer.setProps", p.clone());
|
||||
let after = (s.doc().unwrap().doc.clone(), undos(&s));
|
||||
assert!(after.0 == before.0 && after.1 == before.1, "{p} changes nothing");
|
||||
}
|
||||
run(&mut s, "layer.setProps", json!({"id": sub.0, "locked": true}));
|
||||
assert_eq!(undos(&s), before.1 + 1, "locking the sublayer is one undo step");
|
||||
run(&mut s, "select.set", json!({"ids": [a.0]}));
|
||||
let undo = undos(&s);
|
||||
run(&mut s, "layer.setProps", json!({"id": sub.0, "locked": true}));
|
||||
assert_eq!(undos(&s), undo, "locking it again records no undo step");
|
||||
assert!(s.doc().unwrap().selection.objects.is_empty(), "the art of the locked sublayer is deselected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layer_options_validate_and_template_locks_and_dims() {
|
||||
let mut s = session();
|
||||
|
||||
@@ -1721,8 +1721,7 @@ mod tests {
|
||||
look(&app) != before
|
||||
})
|
||||
};
|
||||
// `layer.setProps {}` and `path.moveAnchors {}` record an undo step that changes nothing.
|
||||
let changed: Vec<&str> = ids.iter().copied().filter(|id| !["layer.setProps", "path.moveAnchors"].contains(id) && acts(id)).collect();
|
||||
let changed: Vec<&str> = ids.iter().copied().filter(|id| acts(id)).collect();
|
||||
assert!(changed.is_empty(), "a pick of these does something: {changed:?}");
|
||||
for c in &dropped {
|
||||
assert!(c.shortcut.is_none() && crate::shortcut_editor::menu_bar_path(c.id).is_none(), "{}", c.id);
|
||||
|
||||
+2
-1
@@ -767,7 +767,7 @@ ends the wait, so the sampler can be shown again. The BSDs and headless sessions
|
||||
| `transform` | `{ids?, dx?, dy?, rotate?, scale?, scaleX?, scaleY?, reflect?, shear?, origin?, copy?}` | Runs move, rotate, scale, reflect, shear in that order. `rotate` is in degrees counter-clockwise; a positive `shear` moves the top to the right. With `copy`, the first step duplicates. A `scale`, `reflect` or `shear` that its command would refuse returns that error before any step runs; nothing changes and no undo step is recorded. The same holds for a step that is neither a number nor null, a `reflect` that is not a string, a `copy` that is not true or false, and an `origin` that is not two numbers. A null `rotate`, `scale`, `scaleX`, `scaleY`, `shear`, `reflect`, `copy` or `origin` is left out; a null `dx` or `dy` counts as 0, so it still runs the move. |
|
||||
| `create_graph` | `{type?, x, y, width, height, csv? \| series?, categories?, rows?}` | The nine Illustrator graph types: column, stacked column, bar, stacked bar, line, area, scatter, pie and radar. An empty CSV cell or a `null` in `rows` is a blank value; a number in straight quotes is a label. Edit later with `graph.setData` / `graph.setType` via `run_command`. `graph.column {design, columnType: vertical\|uniform\|repeating\|sliding, each, fractions: chop\|scale}` draws the columns or bars of the series picked with Group Selection (or `seriesIndexes`, or all of them) with a graph design saved by `graph.design`; with no `design` it returns the series' current design and options. Type in the design that holds a `%` followed by two digits shows each column's value, with at least the first digit's places before the decimal point and the second digit's places after it. |
|
||||
| `text_wrap` | `{ids?, offset?, invert?, release?}` | Area type below the objects (same layer) flows around them. `offset` is in points, from -1000 to 1000 (default 6). An offset outside that range or not a number, or an `invert` or `release` that is not true or false, is an error and changes nothing; `object.textWrap.make` and `object.textWrap.options` refuse the same values. |
|
||||
| `undo` / `redo` | `{}` | Many calls that change nothing record no undo step, for example `object.align` with nothing to move, `object.move` by 0 without `copy` and `object.showAll` with nothing hidden. `undo` (`edit.undo`) after such a call undoes the step before it. Settings that change without an undo step stay as they are when `undo` or `redo` brings back a step that did not change them: the perspective grid's view options and active plane, the grid preferences (`gridlineEvery`, `gridSubdivisions`), the export settings (`assets.settings.set`), and the current brush and symbol. A step that changed one of them, such as a perspective grid preset that shows the grid, takes that change back. The point Automatic Plane Positioning holds comes back with the step, and is let go when the active plane kept is another one. `inspect_document` lists the undo steps as `history`. `run_command` with `edit.clearHistory` removes every undo and redo step of the active document and returns `{cleared}`, the number of steps removed; the document stays as it is, and the command records no undo step. `run_command` with `edit.newDocumentFromState` and `{index?, created?}` makes a new document holding the art as it was at that state and makes it the active document, and returns `{index, title}`. `index` is a row of the History panel, with 0 the oldest state kept, and an omitted or null `index` uses the current state. An `index` that names no state fails with `no history state N`, one that is not a whole number with `` `index` must be a whole number ``, and either changes nothing. `created` is File Info's created date in Unix seconds or null, and defaults to now. The new document takes the next `Untitled-N` name, is marked unsaved, has nothing selected and has no steps to undo or redo. It is out of symbol, opacity-mask and pattern editing, and the art drawn in a pattern's tile is stored in the pattern, as `object.pattern.done` stores it. The source document and its steps stay as they are, except that typing or a drag in progress is first kept as a step. When a command keeps a drag whose preview Real-time Drawing off had not applied yet (`edit.undo`, `edit.redo`, `edit.clearHistory`, `edit.newDocumentFromState` and the other commands that end a drag first), and applying that preview gives a warning, the command's result carries it as `previewWarning`, and as `warning` too when the command gives no warning of its own; the app's status bar shows `warning`. Any other command that changes the document during a tool's drag, from `run_command`, a panel or a menu, records its own undo step before the drag's. The command acts on the document without the drag's preview, and the drag then continues from the command's result: with Real-time Drawing on, the drag's preview is applied again at once, and with it off, the release applies it as before. The release records the drag's step after the command's, `undo` takes back the drag first and the command next, and Escape cancels only the drag. The drag acts on the objects it started with, so a selection the command makes (`select.all`, `edit.duplicate`) does not change what the drag moves, and the drag's release and Escape set the selection as they do without the command (with Real-time Drawing on, so does each move of the drag); a command that records no undo step, such as `select.none`, adds no step. When the command deletes or changes the art being dragged, the drag continues with the art the command left, and a drag left with nothing to change records no step. A warning or an error from the drag's preview applied again after the command is in the command's result as `previewWarning`. Typing in progress is kept as a step of its own before the command. Two cases run the command inside the drag, which then keeps the command's edit as part of its own step: a press of the Quick Pen (an edit to its path ends the path), and `object.transform` with `copy` during an Alt-drag, which copies the art as the drag's move left it. A command run while a dialog's or a panel's preview is open runs inside that preview. While the Type tool edits type, `undo` and `redo` put its caret, with no characters selected, at the end of the text the step changed: after the text it puts back or retypes, or where the text it takes out was. A step that changes no characters, such as a formatting change, leaves the caret and the selection where they are. |
|
||||
| `undo` / `redo` | `{}` | Many calls that change nothing record no undo step, for example `object.align` with nothing to move, `object.move` by 0 without `copy`, `path.moveAnchors` by 0, `layer.setProps` with every row already as given and `object.showAll` with nothing hidden. `undo` (`edit.undo`) after such a call undoes the step before it. Settings that change without an undo step stay as they are when `undo` or `redo` brings back a step that did not change them: the perspective grid's view options and active plane, the grid preferences (`gridlineEvery`, `gridSubdivisions`), the export settings (`assets.settings.set`), and the current brush and symbol. A step that changed one of them, such as a perspective grid preset that shows the grid, takes that change back. The point Automatic Plane Positioning holds comes back with the step, and is let go when the active plane kept is another one. `inspect_document` lists the undo steps as `history`. `run_command` with `edit.clearHistory` removes every undo and redo step of the active document and returns `{cleared}`, the number of steps removed; the document stays as it is, and the command records no undo step. `run_command` with `edit.newDocumentFromState` and `{index?, created?}` makes a new document holding the art as it was at that state and makes it the active document, and returns `{index, title}`. `index` is a row of the History panel, with 0 the oldest state kept, and an omitted or null `index` uses the current state. An `index` that names no state fails with `no history state N`, one that is not a whole number with `` `index` must be a whole number ``, and either changes nothing. `created` is File Info's created date in Unix seconds or null, and defaults to now. The new document takes the next `Untitled-N` name, is marked unsaved, has nothing selected and has no steps to undo or redo. It is out of symbol, opacity-mask and pattern editing, and the art drawn in a pattern's tile is stored in the pattern, as `object.pattern.done` stores it. The source document and its steps stay as they are, except that typing or a drag in progress is first kept as a step. When a command keeps a drag whose preview Real-time Drawing off had not applied yet (`edit.undo`, `edit.redo`, `edit.clearHistory`, `edit.newDocumentFromState` and the other commands that end a drag first), and applying that preview gives a warning, the command's result carries it as `previewWarning`, and as `warning` too when the command gives no warning of its own; the app's status bar shows `warning`. Any other command that changes the document during a tool's drag, from `run_command`, a panel or a menu, records its own undo step before the drag's. The command acts on the document without the drag's preview, and the drag then continues from the command's result: with Real-time Drawing on, the drag's preview is applied again at once, and with it off, the release applies it as before. The release records the drag's step after the command's, `undo` takes back the drag first and the command next, and Escape cancels only the drag. The drag acts on the objects it started with, so a selection the command makes (`select.all`, `edit.duplicate`) does not change what the drag moves, and the drag's release and Escape set the selection as they do without the command (with Real-time Drawing on, so does each move of the drag); a command that records no undo step, such as `select.none`, adds no step. When the command deletes or changes the art being dragged, the drag continues with the art the command left, and a drag left with nothing to change records no step. A warning or an error from the drag's preview applied again after the command is in the command's result as `previewWarning`. Typing in progress is kept as a step of its own before the command. Two cases run the command inside the drag, which then keeps the command's edit as part of its own step: a press of the Quick Pen (an edit to its path ends the path), and `object.transform` with `copy` during an Alt-drag, which copies the art as the drag's move left it. A command run while a dialog's or a panel's preview is open runs inside that preview. While the Type tool edits type, `undo` and `redo` put its caret, with no characters selected, at the end of the text the step changed: after the text it puts back or retypes, or where the text it takes out was. A step that changes no characters, such as a formatting change, leaves the caret and the selection where they are. |
|
||||
|
||||
For example, create editable Japanese area type with the engine's vertical writing mode:
|
||||
|
||||
@@ -7107,6 +7107,7 @@ and `layerRows`, the rows highlighted in the panel.
|
||||
draws and is clicked in outline, Ctrl/Cmd-click its eye), `dimImages` (0–100, or false) and `color` (an index 0–26,
|
||||
`#rrggbb` or a preset name; a hex color with an alpha part, `#rrggbbaa` or `#rgba`, is an error, and so it is in
|
||||
`layer.new` and `layer.newSublayer`). Several rows change in one undo step (a drag down the eye or lock column).
|
||||
When every row already has every option given, the call records no undo step.
|
||||
A ruler guide's row has its own eye and lock: `ids` may name ruler guides (their `id` in `guide.list`), which take
|
||||
`visible` and `locked`. They can be changed while the guide's layer is hidden or locked, and the guide shows
|
||||
or can be edited only when its layer allows it as well. Alt-click on a guide row's eye or lock acts on the other
|
||||
|
||||
Reference in new issue
Block a user