mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-06 05:53:08 -05:00
Plug-ins: an outside command leaves recut paths and a refused step alone
During an add-on dialog's preview, a command from outside the dialog no longer acts on a path whose selected anchors the preview renumbered (Set Corners recut it), so Clear does not delete other points of the base path. A refused outside command leaves the dialog's own selection as it was, while a command that ran, such as Deselect, still sets it. The journal records the selection the command acts on before it, so an action replays it on the same objects.
This commit is contained in:
1 parent
8eacad4a69
commit
168d6c9cce
4 files changed
+124
-8
No files matched your search
@@ -104,6 +104,10 @@ pub(crate) struct HeldInteraction {
|
||||
/// The new-art paints when the command began: a change the command makes to them stays when
|
||||
/// the interaction's next preview or a cancel puts back the paints it began with.
|
||||
pub(crate) paint: vectorcraft_tools::PaintDefaults,
|
||||
/// The command's own selection steps went into the journal before it ran.
|
||||
pub(crate) journaled: bool,
|
||||
/// The command returned an error.
|
||||
pub(crate) refused: bool,
|
||||
}
|
||||
|
||||
/// The per-document state an interaction puts back when it is canceled, besides the document and
|
||||
|
||||
@@ -345,8 +345,10 @@ impl Session {
|
||||
///
|
||||
/// A dialog's live preview ([`crate::Interaction::dialog`]) is set aside the same way, except
|
||||
/// for a command that acts on the drawing on show ([`reads_preview`]). Outside commands use
|
||||
/// the shown selection with objects absent from the base document removed. A selection of
|
||||
/// only preview objects becomes empty. The interaction stays as it is, and the command runs
|
||||
/// the shown selection with objects absent from the base document removed, and without a path
|
||||
/// whose selected anchors the preview renumbered. A selection of only preview objects becomes
|
||||
/// empty. The journal records that selection before the command, and records the dialog's
|
||||
/// own selection again when the command is refused. The interaction stays as it is, and the command runs
|
||||
/// inside it, for an interaction a panel or
|
||||
/// another dialog began (it builds its preview from commands), for typing in progress
|
||||
/// ([`Session::edit`] keeps it as a step of its own), for the Quick Pen (an edit made outside
|
||||
@@ -372,21 +374,35 @@ impl Session {
|
||||
let shown = previewed.then(|| (st.doc.clone(), st.selection.clone()));
|
||||
if previewed {
|
||||
st.doc = interaction.doc.clone();
|
||||
if interaction.dialog {
|
||||
st.selection.prune(&st.doc);
|
||||
if let Some((shown_doc, _)) = shown.as_ref().filter(|_| interaction.dialog) {
|
||||
shown_base_selection(&mut st.selection, shown_doc, &st.doc);
|
||||
} else {
|
||||
st.selection.clone_from(&interaction.selection);
|
||||
}
|
||||
st.revision += 1;
|
||||
cmd::globaledit::follow_history(st);
|
||||
}
|
||||
// The journal holds the dialog's base selection, so the command replays on the one it acts on.
|
||||
let reselect = (interaction.dialog && st.selection != *interaction.selection)
|
||||
.then(|| selection_steps(&st.selection, &interaction.selection, &st.doc, st.active_layer, &st.highlighted_rows()));
|
||||
let (uid, state) = (st.uid, crate::interaction::ViewState::of(st));
|
||||
let paint = self.paint.clone();
|
||||
self.held_interaction = Some(crate::HeldInteraction { uid, interaction, shown, state, paint });
|
||||
let journaled = reselect.is_some();
|
||||
if let Some(steps) = reselect {
|
||||
let (from, grouped) = (self.journal.len(), self.undo_group_docs());
|
||||
for step in steps {
|
||||
self.journal.push(step);
|
||||
}
|
||||
self.journal_in_undo_groups(Some(uid), &grouped, from);
|
||||
}
|
||||
self.held_interaction = Some(crate::HeldInteraction { uid, interaction, shown, state, paint, journaled, refused: false });
|
||||
if previewed {
|
||||
self.sync_front_profiles();
|
||||
}
|
||||
let r = f(self);
|
||||
if let Some(held) = self.held_interaction.as_mut().filter(|_| r.is_err()) {
|
||||
held.refused = true;
|
||||
}
|
||||
self.put_back_interaction();
|
||||
r
|
||||
}
|
||||
@@ -402,7 +418,9 @@ impl Session {
|
||||
/// than a move. A document the command left an interaction of its own on keeps that one.
|
||||
/// A dialog adopts the command's selection and paints and reruns its preview on its next pass.
|
||||
pub(crate) fn put_back_interaction(&mut self) {
|
||||
let Some(crate::HeldInteraction { uid, interaction: mut it, shown, state, paint }) = self.held_interaction.take() else { return };
|
||||
let Some(crate::HeldInteraction { uid, interaction: mut it, shown, state, paint, journaled, refused }) = self.held_interaction.take() else {
|
||||
return;
|
||||
};
|
||||
// A selection command loaded the paints of the selection it made into the fill and stroke
|
||||
// proxies. The drag goes on with its own selection, so they show its paints again.
|
||||
if !it.dialog
|
||||
@@ -460,7 +478,19 @@ impl Session {
|
||||
// isolation stays when the interaction is canceled.
|
||||
state.rebase(crate::interaction::ViewState::of(st), &mut it);
|
||||
let previewed = shown.is_some();
|
||||
if Arc::ptr_eq(&st.doc, &it.doc) && st.selection == *it.selection {
|
||||
// A refused command leaves the selection it was given: a dialog's is the one on show without
|
||||
// preview objects. A command that ran (Deselect) and left that selection keeps it.
|
||||
let given = match shown.as_ref().filter(|_| it.dialog && refused) {
|
||||
Some((shown_doc, selection)) => {
|
||||
let mut given = selection.clone();
|
||||
shown_base_selection(&mut given, shown_doc, &it.doc);
|
||||
given
|
||||
}
|
||||
None => (*it.selection).clone(),
|
||||
};
|
||||
if Arc::ptr_eq(&st.doc, &it.doc) && st.selection == given {
|
||||
// The journal goes back to the dialog's base selection, as the preview on show again holds it.
|
||||
let back = (journaled && active).then(|| selection_steps(&it.selection, &given, &st.doc, st.active_layer, &st.highlighted_rows()));
|
||||
if let Some((doc, selection)) = shown {
|
||||
st.doc = doc;
|
||||
st.selection = selection;
|
||||
@@ -468,6 +498,13 @@ impl Session {
|
||||
cmd::globaledit::follow_history(st);
|
||||
}
|
||||
st.interaction = Some(it);
|
||||
if let Some(steps) = back {
|
||||
let (from, grouped) = (self.journal.len(), self.undo_group_docs());
|
||||
for step in steps {
|
||||
self.journal.push(step);
|
||||
}
|
||||
self.journal_in_undo_groups(Some(uid), &grouped, from);
|
||||
}
|
||||
if previewed {
|
||||
self.sync_front_profiles();
|
||||
}
|
||||
@@ -970,6 +1007,33 @@ fn reads_preview(id: &str) -> bool {
|
||||
id == "edit.copy" || (id.starts_with("file.") && id != "file.documentColorMode")
|
||||
}
|
||||
|
||||
/// The selection on show in a dialog's preview `shown`, as a command from outside the dialog acts
|
||||
/// on it in the base document `base`: without the objects the preview made, and without a path
|
||||
/// whose selected anchors or segments are numbered in a shape the preview changed in more than a
|
||||
/// move (Set Corners recut it), since those numbers can name other points in `base`.
|
||||
fn shown_base_selection(selection: &mut Selection, shown: &Document, base: &Document) {
|
||||
selection.prune(base);
|
||||
let recut: Vec<_> = selection
|
||||
.anchors
|
||||
.keys()
|
||||
.chain(selection.segments.keys())
|
||||
.copied()
|
||||
.filter(|&id| {
|
||||
let path = |d: &Document| d.node(id).and_then(|n| n.path_data()).map(|p| p.subpaths.clone());
|
||||
match (path(shown), path(base)) {
|
||||
(Some(now), Some(was)) => !moved_whole(&was, &now),
|
||||
(now, was) => now.is_some() != was.is_some(),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
for id in recut {
|
||||
selection.objects.retain(|o| *o != id);
|
||||
selection.anchors.remove(&id);
|
||||
selection.segments.remove(&id);
|
||||
}
|
||||
selection.prune(base);
|
||||
}
|
||||
|
||||
/// The selection a drag began with, without the objects that a command run during it removed,
|
||||
/// hid or locked in `doc`.
|
||||
fn drag_selection(began: &Selection, doc: &Document) -> Selection {
|
||||
|
||||
@@ -354,6 +354,54 @@ fn clearing_a_dialog_preview_uses_only_the_shown_base_objects() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clearing_anchors_of_a_path_the_preview_recut_keeps_the_base_path() {
|
||||
let mut app = two_rects_filled();
|
||||
let original = app.session.active().unwrap().doc.clone();
|
||||
let ids = app.session.active().unwrap().selection.objects.clone();
|
||||
app.run("select.anchors", json!({"id": ids[0].0, "anchors": [[0, 1]], "mode": "set"})).unwrap();
|
||||
let mut preview = crate::dialogs::preview::LivePreview::default();
|
||||
assert!(preview.run(&mut app, true, "Set Corners", "addon.pathtools.cornerSet", &json!({"radius": 2, "kind": "chamfer"})).unwrap().is_ok());
|
||||
preview.keep_outside_edits(&mut app);
|
||||
assert!(!app.session.active().unwrap().selection.anchors.is_empty(), "anchors on the recut path are on show");
|
||||
let _refused = app.run("edit.clear", json!({}));
|
||||
preview.cancel(&mut app);
|
||||
assert_eq!(app.session.active().unwrap().doc, original, "Clear deletes no anchor of the base path");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_refused_outside_command_keeps_the_dialog_selection() {
|
||||
let mut app = two_rects_filled();
|
||||
let selected = app.session.active().unwrap().selection.objects.clone();
|
||||
let mut preview = crate::dialogs::preview::LivePreview::default();
|
||||
assert!(preview.run(&mut app, true, "Flood Fill Artboards", "addon.document.floodFillArtboards", &json!({})).unwrap().is_ok());
|
||||
preview.keep_outside_edits(&mut app);
|
||||
let shown = app.session.active().unwrap().selection.clone();
|
||||
assert!(app.run("edit.clear", json!({})).is_err(), "only preview objects are selected");
|
||||
let state = app.session.active().unwrap();
|
||||
assert_eq!(state.interaction.as_ref().unwrap().selection.objects, selected, "the dialog keeps its own selection");
|
||||
assert_eq!(state.selection, shown, "the preview's selection is on show again");
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
assert!(app.session.active().unwrap().interaction.as_ref().unwrap().selection.objects.is_empty(), "Deselect still deselects");
|
||||
preview.cancel(&mut app);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_outside_command_journals_the_selection_it_acts_on() {
|
||||
let mut app = two_rects_filled();
|
||||
let selected = app.session.active().unwrap().selection.objects.clone();
|
||||
let mut preview = crate::dialogs::preview::LivePreview::default();
|
||||
assert!(preview.run(&mut app, true, "Flood Fill Artboards", "addon.document.floodFillArtboards", &json!({})).unwrap().is_ok());
|
||||
preview.keep_outside_edits(&mut app);
|
||||
app.session.active_mut().unwrap().selection.add(selected[0]);
|
||||
let start = app.session.journal_for_action(0).len();
|
||||
app.run("edit.clear", json!({})).unwrap();
|
||||
let action = app.session.journal_for_action(start);
|
||||
let clear = action.iter().position(|(id, _)| id == "edit.clear").unwrap();
|
||||
assert!(action[..clear].iter().any(|(id, _)| id.starts_with("select.")), "Clear replays on the shown selection: {action:?}");
|
||||
preview.cancel(&mut app);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_failed_dialog_preview_retries_after_an_outside_selection_change() {
|
||||
let mut app = two_rects();
|
||||
|
||||
+1
-1
@@ -889,7 +889,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. A type object in `ids` with another of them above it in its layer is the text to wrap, not a wrap object, so the objects and the type can be selected together. The reply has a `warning` when no area type lies below any of the wrap objects. `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`, `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, except during an add-on dialog's preview (Object › Plug-ins, other than Edit Points Only): there a command that changes the document records its own undo step, acts on the document without the preview using the shown selection restricted to objects present in that document, and stays after the dialog's Cancel or OK. A shown selection containing only preview objects becomes empty for the command. The dialog previews again from the command's result and selection, including after a failed preview when only the selection changed. An outside selection command's selection and paint defaults stay together after Cancel or OK. `edit.copy` and the `file.*` commands other than `file.documentColorMode` still run on the document as the preview shows it. While the Type tool edits type, `undo` and `redo` put its caret, with no charactLine truncated
|
||||
| `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, except during an add-on dialog's preview (Object › Plug-ins, other than Edit Points Only): there a command that changes the document records its own undo step, acts on the document without the preview using the shown selection restricted to objects present in that document, and stays after the dialog's Cancel or OK. A shown selection containing only preview objects becomes empty for the command. A path whose selected anchors or segments the preview renumbered (Set Corners recut it) is left out of that selection, so Clear does not delete its points. A command that is refused leaves the dialog's selection as it was. The dialog previews again from the command's result and selection, including after a failed preview when only the selection changed. An outside selection command's selection and paint defaults stay together afLine truncated
|
||||
| `agent_folders` | `{}` | Where VectorCraft opens and saves files for this session: `{read_folder, write_folder}`, each a path or `null`. In the open window, the agent folders of Preferences › AI Integrations (`Documents/ArtCraft/Agents/VectorCraft` for an empty one); in a headless session started for agents, the folders it was confined to (`read_folders` / `write_folders` list them all when a kind has several); a session started without automation roots answers `unrestricted: true`. An app reached with the deprecated `--connect` answers an error: its own `--automation-*-root` flags, if any, confine it. |
|
||||
|
||||
For example, create editable Japanese area type with the engine's vertical writing mode:
|
||||
|
||||
Reference in new issue
Block a user