Merge pull request #8145 from dotCooCoo/feat/expand-alt-skips-dialog

Expand: Alt/Option on Object › Expand… expands at once with the last OK'd choices
This commit is contained in:
BFlat
2026-11-18 10:12:33 +07:00
committed by GitHub
8 changed files with 213 additions and 12 deletions
+1 -1
View File
@@ -1269,7 +1269,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"ui.expandDialog",
"Expand…",
"",
"{} open Expand for the selection (dialog `expand`, fields object, fill, stroke (all on; one the selection has nothing for is disabled, see object.expand.info), gradient: objects|mesh, steps 1..1000 (255)): OK runs object.expand with them as one undo step; dimmed, and an error, while the selection has an appearance effect.expandAppearance expands (object.expand.info's appearance)",
"{immediate?: bool (false)} open Expand for the selection (dialog `expand`, fields object, fill, stroke (all on; one the selection has nothing for is disabled, see object.expand.info), gradient: objects|mesh, steps 1..1000 (255), or the choices OK last expanded with since the app started): OK runs object.expand with them as one undo step and keeps them until the app quits; immediate: true (the menu item chosen with Alt/Option) runs object.expand at once with those choices (the defaults before any OK), and opens the dialog instead when none of them has something to expand in the selection; dimmed, and an error, while the selection has an appearance effect.expandAppearance expands (object.expand.info's appearance)",
),
(
"attributes.openUrl",
+185 -8
View File
@@ -1,7 +1,9 @@
//! Object → Expand: what to expand (Object: live shapes, type and effects; Fill: gradient and pattern fills;
//! Stroke: strokes into filled outlines) and what gradient fills become (a gradient mesh, or a
//! number of objects). Options the selection has nothing for are disabled. OK runs
//! `object.expand` as one undo step.
//! `object.expand` as one undo step and keeps its choices for the rest of the app's run: the dialog
//! opens on them, and Object › Expand… chosen with Alt (Option) expands with them at once
//! ([`expand_now`]).
//!
//! Fields: `object`, `fill`, `stroke`, `gradient` (`objects` | `mesh`), `steps` (1..1000), and
//! `__object`, `__fill`, `__stroke` (that option has something to expand: `object.expand.info`),
@@ -31,15 +33,51 @@ pub(crate) fn appearance_first() -> &'static str {
tl!("Expand Appearance first (Object › Expand Appearance)")
}
/// Open Expand for the selection, every option on (as `object.expand {}` does). A selection with
/// appearance attributes (effects, several fills or strokes…) refuses with [`appearance_first`]:
/// the menu item is dimmed for it.
/// Open Expand for the selection, on the choices OK last expanded with in this run of the app, or
/// every option on (as `object.expand {}` does) before that. A selection with appearance attributes
/// (effects, several fills or strokes…) refuses with [`appearance_first`]: the menu item is dimmed
/// for it.
pub fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
let fields = fields(app)?;
app.ui.dialog = Some(Dialog::new(KIND, fields));
Ok(Value::Null)
}
/// Object › Expand… chosen with Alt (Option): expand the selection at once, in one undo step, with
/// the choices OK last expanded with in this run of the app (the dialog's defaults before that), as
/// OK in the dialog opened on them would. When none of those choices has something to expand in the
/// selection, the dialog opens on them instead, and nothing changes. A selection with appearance
/// attributes refuses with [`appearance_first`], as [`open`] does.
pub fn expand_now(app: &mut VectorcraftApp) -> Result<Value, String> {
let d = Dialog::new(KIND, fields(app)?);
if !OPTIONS.iter().any(|(key, _)| d.bool(key) && option_enabled(&d, key)) {
app.ui.dialog = Some(d);
return Ok(Value::Null);
}
app.run(CMD, params(&d))
}
/// The choices OK last expanded with (`app.ui.expand_options`), when each one holds a value the
/// dialog shows: a switch for Object, Fill and Stroke, `objects` or `mesh`, and 1 to 1000 steps.
fn remembered(app: &VectorcraftApp) -> Option<&Value> {
let o = &app.ui.expand_options;
let switches = OPTIONS.iter().all(|(key, _)| o[key].is_boolean());
let gradient = matches!(o["gradient"].as_str(), Some("objects" | "mesh"));
let steps = o["steps"].as_f64().is_some_and(|n| (1.0..=MAX_STEPS as f64).contains(&n.round()));
(switches && gradient && steps).then_some(o)
}
/// The dialog's fields for the selection: the remembered choices (or the defaults) and what each
/// option has to expand.
fn fields(app: &mut VectorcraftApp) -> Result<Value, String> {
let info = app.session.execute("object.expand.info", &json!({})).map_err(|e| e.to_string())?;
if info["appearance"] == json!(true) {
return Err(appearance_first().into());
}
let mut fields = json!({"object": true, "fill": true, "stroke": true, "gradient": "objects", "steps": DEFAULT_STEPS});
let mut fields = match remembered(app) {
Some(o) => json!({"object": o["object"], "fill": o["fill"], "stroke": o["stroke"], "gradient": o["gradient"], "steps": o["steps"]}),
None => json!({"object": true, "fill": true, "stroke": true, "gradient": "objects", "steps": DEFAULT_STEPS}),
};
for (key, _) in OPTIONS {
fields[format!("__{key}")] = info[key].clone();
}
@@ -47,8 +85,7 @@ pub fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
for key in ["fill", "stroke", "gradient"] {
fields[format!("__{key}_symbol")] = json!(info["symbolArt"][key] == json!(true));
}
app.ui.dialog = Some(Dialog::new(KIND, fields));
Ok(Value::Null)
Ok(fields)
}
fn body(_: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool {
@@ -112,8 +149,12 @@ fn params(d: &Dialog) -> Value {
})
}
/// OK: expand, and keep the choices once the expansion succeeded.
fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result<Value, String> {
run_and_close(app, CMD, params(d))
let choices = params(d);
let r = run_and_close(app, CMD, choices.clone())?;
app.ui.expand_options = choices;
Ok(r)
}
#[cfg(test)]
@@ -253,4 +294,140 @@ mod tests {
app.run("select.none", json!({})).unwrap();
assert!(!crate::menus::enabled(&app, "ui.expandDialog"));
}
/// A rectangle with a linear gradient fill and no stroke is selected.
fn gradient_rectangle(app: &mut VectorcraftApp) {
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
app.run("shape.rectangle", json!({"x": 20, "y": 20, "width": 100, "height": 60})).unwrap();
app.run("paint.setFill", json!({"gradient": {"kind": "linear"}})).unwrap();
app.run("paint.setStroke", json!({"none": true})).unwrap();
}
/// Object › Expand… from the in-window menu, with Alt held or not.
fn choose_expand(app: &mut VectorcraftApp, alt: bool) {
let entries = crate::menus::menu_entries(app);
let e = entries.iter().find(|e| e.path == ["Object"] && e.label == "Expand…").expect("Object › Expand…");
assert!(e.enabled, "Expand… is available");
let target = crate::menus::click_target(&e.label, e.command.as_deref().unwrap(), &e.params);
let held = if alt { egui::Modifiers::ALT } else { egui::Modifiers::NONE };
let (cmd, p) = crate::menus::with_held_keys(target, held);
crate::menus::invoke(app, &cmd, p);
}
/// Whether the selected object is a clip group holding a gradient mesh (Expand Gradient To ›
/// Gradient Mesh) rather than solid objects.
fn expanded_to_a_mesh(app: &VectorcraftApp) -> bool {
let st = app.session.doc().unwrap();
let g = st.doc.node(st.selection.objects[0]).unwrap();
let NodeKind::Group { children, clip: true } = &g.kind else { panic!("a clip group: {:?}", g.kind) };
children.iter().any(|c| matches!(c.kind, NodeKind::Mesh(_)))
}
#[test]
fn the_dialog_opens_on_the_choices_ok_last_expanded_with() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
gradient_rectangle(&mut app);
choose_expand(&mut app, false);
let d = app.ui.dialog.as_mut().expect("the Expand dialog");
d.fields.insert("gradient".into(), json!("mesh"));
d.fields.insert("steps".into(), json!(12));
d.fields.insert("stroke".into(), json!(false));
super::super::confirm(&mut app).unwrap();
assert!(expanded_to_a_mesh(&app));
app.run("edit.undo", json!({})).unwrap();
let kept = json!({"object": true, "fill": true, "stroke": false, "gradient": "mesh", "steps": 12.0});
choose_expand(&mut app, false);
assert_eq!(params(app.ui.dialog.as_ref().unwrap()), kept, "it opens on the choices OK expanded with");
// Cancel leaves them as they were.
app.ui.dialog.as_mut().unwrap().fields.insert("gradient".into(), json!("objects"));
super::super::cancel(&mut app);
assert_eq!(app.ui.expand_options, kept);
// So does an OK that fails, and nothing changes.
choose_expand(&mut app, false);
app.ui.dialog.as_mut().unwrap().fields.insert("steps".into(), json!(5000));
let before = app.session.doc().unwrap().doc.clone();
assert!(super::super::confirm(&mut app).is_err());
assert_eq!(app.session.doc().unwrap().doc, before);
assert_eq!(app.ui.expand_options, kept);
choose_expand(&mut app, false);
assert_eq!(params(app.ui.dialog.as_ref().unwrap()), kept);
}
#[test]
fn alt_expands_at_once_with_the_choices_ok_last_expanded_with() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
gradient_rectangle(&mut app);
choose_expand(&mut app, false);
app.ui.dialog.as_mut().unwrap().fields.insert("gradient".into(), json!("mesh"));
super::super::confirm(&mut app).unwrap();
app.run("edit.undo", json!({})).unwrap();
let undo = app.session.doc().unwrap().history.undo.len();
choose_expand(&mut app, true);
assert!(app.ui.dialog.is_none(), "no dialog");
assert_eq!(app.session.doc().unwrap().history.undo.len(), undo + 1, "one undo step");
assert!(expanded_to_a_mesh(&app), "the kept Gradient Mesh choice");
}
#[test]
fn alt_before_any_ok_expands_with_the_defaults() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
gradient_rectangle(&mut app);
let undo = app.session.doc().unwrap().history.undo.len();
choose_expand(&mut app, true);
assert!(app.ui.dialog.is_none(), "no dialog");
assert_eq!(app.session.doc().unwrap().history.undo.len(), undo + 1);
assert!(!expanded_to_a_mesh(&app), "the gradient becomes objects, the default");
assert!(app.ui.expand_options.is_null(), "Alt keeps no choices of its own");
}
#[test]
fn alt_opens_the_dialog_when_the_kept_choices_expand_nothing_in_the_selection() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
app.run("shape.rectangle", json!({"x": 20, "y": 20, "width": 100, "height": 60})).unwrap();
// Fill alone was kept, and a plain rectangle has no gradient or pattern fill.
app.ui.expand_options = json!({"object": false, "fill": true, "stroke": false, "gradient": "objects", "steps": 255.0});
let before = app.session.doc().unwrap().doc.clone();
let undo = app.session.doc().unwrap().history.undo.len();
choose_expand(&mut app, true);
let d = app.ui.dialog.as_ref().expect("the Expand dialog");
assert_eq!(params(d), app.ui.expand_options, "it opens on the kept choices");
assert_eq!(app.session.doc().unwrap().history.undo.len(), undo, "nothing recorded");
assert_eq!(app.session.doc().unwrap().doc, before);
}
#[test]
fn alt_refuses_a_selection_with_appearance_attributes_and_a_bad_immediate() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
zig_zag_line(&mut app);
let before = app.session.doc().unwrap().doc.clone();
assert_eq!(app.run("ui.expandDialog", json!({"immediate": true})).unwrap_err(), appearance_first());
assert!(app.ui.dialog.is_none());
assert_eq!(app.session.doc().unwrap().doc, before, "the line is left as it was");
app.run("effect.expandAppearance", json!({})).unwrap();
assert!(app.run("ui.expandDialog", json!({"immediate": "yes"})).is_err());
assert!(app.ui.dialog.is_none());
app.run("ui.expandDialog", json!({"immediate": false})).unwrap();
assert_eq!(app.ui.dialog.as_ref().map(|d| d.kind.as_str()), Some(KIND));
}
#[test]
fn kept_choices_with_a_value_the_dialog_does_not_show_are_left_out() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
gradient_rectangle(&mut app);
for bad in [
json!({"object": "yes", "fill": true, "stroke": true, "gradient": "mesh", "steps": 12}),
json!({"object": true, "fill": true, "stroke": true, "gradient": "strips", "steps": 12}),
json!({"object": true, "fill": true, "stroke": true, "gradient": "mesh", "steps": 0}),
json!({"object": true, "fill": true, "stroke": true, "gradient": "mesh"}),
] {
app.ui.expand_options = bad;
app.run("ui.expandDialog", json!({})).unwrap();
assert_eq!(
params(app.ui.dialog.as_ref().unwrap()),
json!({"object": true, "fill": true, "stroke": true, "gradient": "objects", "steps": 255.0})
);
app.ui.dialog = None;
}
}
}
+3 -1
View File
@@ -17,10 +17,12 @@ pub fn click_target(label: &str, id: &str, p: &Value) -> (String, Value) {
/// What an in-window menu click on `target` (a [`click_target`]) runs with `held` held: Object ›
/// Unlock All and Object › Show All chosen with Shift+Alt (Shift+Option) act only inside the groups
/// that hold the selected objects (`scope: "group"`); Select Linked, Embedded, Missing and Modified
/// chosen with Shift add to the selection (`add: true`).
/// chosen with Shift add to the selection (`add: true`); Object › Expand… chosen with Alt (Option)
/// expands at once with the choices its dialog last expanded with (`immediate: true`).
pub(crate) fn with_held_keys(target: (String, Value), held: egui::Modifiers) -> (String, Value) {
match target.0.as_str() {
"object.unlockAll" | "object.showAll" if held.shift && held.alt => (target.0, json!({"scope": "group"})),
"ui.expandDialog" if held.alt => (target.0, json!({"immediate": true})),
// Select Linked, Embedded, Missing and Modified with Shift add to the selection.
crate::addons::select::link_status::COMMAND if held.shift => (target.0, crate::addons::select::link_status::with_shift(target.1)),
_ => target,
+5 -1
View File
@@ -905,7 +905,11 @@ fn run_ui_part9(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<Result<
fn run_ui_part10(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<Result<Value, String>> {
let s = |k: &str| p.get(k).and_then(Value::as_str).map(str::to_string);
let r = match id {
"ui.expandDialog" => crate::dialogs::expand::open(app),
"ui.expandDialog" => match opt_bool(p, "immediate") {
Ok(Some(true)) => crate::dialogs::expand::expand_now(app),
Ok(_) => crate::dialogs::expand::open(app),
Err(e) => Err(e),
},
"ui.simplifyAuto" => crate::dialogs::simplify_slider::auto(app),
"ui.simplifyMoreOptions" => crate::dialogs::simplify_slider::more_options(app),
"ui.smoothAuto" => crate::dialogs::smooth_slider::auto(app),
+1 -1
View File
@@ -1270,7 +1270,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
"ui.expandDialog",
"Expand…",
"",
"{} open Expand for the selection (dialog `expand`, fields object, fill, stroke (all on; one the selection has nothing for is disabled, see object.expand.info), gradient: objects|mesh, steps 1..1000 (255)): OK runs object.expand with them as one undo step; dimmed, and an error, while the selection has an appearance effect.expandAppearance expands (object.expand.info's appearance)",
"{immediate?: bool (false)} open Expand for the selection (dialog `expand`, fields object, fill, stroke (all on; one the selection has nothing for is disabled, see object.expand.info), gradient: objects|mesh, steps 1..1000 (255), or the choices OK last expanded with since the app started): OK runs object.expand with them as one undo step and keeps them until the app quits; immediate: true (the menu item chosen with Alt/Option) runs object.expand at once with those choices (the defaults before any OK), and opens the dialog instead when none of them has something to expand in the selection; dimmed, and an error, while the selection has an appearance effect.expandAppearance expands (object.expand.info's appearance)",
),
(
"attributes.openUrl",
+6
View File
@@ -832,6 +832,11 @@ pub struct UiState {
/// them (#1732).
#[serde(default)]
pub transform_each: Value,
/// The Expand choices OK last expanded with in this run of the app (object, fill, stroke,
/// gradient, steps; null: none yet): the Expand dialog opens on them, and Object › Expand…
/// chosen with Alt (Option) expands with them at once. They are not kept across launches.
#[serde(skip)]
pub expand_options: Value,
/// The spacing used the last time Rearrange All Artboards was confirmed.
#[serde(default)]
pub rearrange_artboards_spacing: Value,
@@ -1271,6 +1276,7 @@ impl Default for UiState {
simplify: Value::Null,
move_options: Value::Null,
transform_each: Value::Null,
expand_options: Value::Null,
rearrange_artboards_spacing: Value::Null,
dxf_import: Value::Null,
psd_import: Value::Null,
+11
View File
@@ -5787,6 +5787,17 @@ link, the dimension stays where it was, no longer linked (see [dimensions.md](di
`object.expand` rejects a param of the wrong type, such as `"fill": "yes"`, `"gradient": 3` or `"steps": "16"`, and
changes nothing. Omitting a param or giving null keeps its default.
`ui.expandDialog {immediate?}` opens the Expand dialog (`object.expand` with no params opens it too). The dialog opens on
the Object, Fill, Stroke, Expand Gradient To and steps choices that OK last expanded with since the app started, and on
the defaults before that; Cancel and an OK that fails leave the kept choices as they were, and they are not kept across
launches. Choosing Object → Expand… in the in-window menu bar with Alt (Option on macOS) held sends `immediate: true`, which expands the selection
at once with those choices, or the defaults before any OK, in one undo step, as OK in the dialog would
([the help page](https://helpx.adobe.com/illustrator/desktop/manage-objects/arrange-objects/expand-objects.html)
describes this shortcut for a gradient; VectorCraft applies it to whatever the choices expand). When none of the kept
choices has something to expand in the selection, `immediate: true` opens the dialog on them instead and changes
nothing. A selection with appearance attributes refuses both, as the dimmed menu item does. An `immediate` of null is
treated as omitted, and any other value that is not true or false is an error.
```json
{"name":"run_command","arguments":{"command":"object.expand","params":{"stroke":false,"gradient":"mesh"}}}
{"name":"run_command","arguments":{"command":"object.expand","params":{"steps":16}}}
+1
View File
@@ -2242,6 +2242,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- **Pattern fills in Expand:** Object › Expand with Fill turns a pattern fill into the pattern's tiles in a clip group shaped like the object, with the fill's opacity and blend mode, and the object's other fills and strokes stay above or below it in paint order, in one undo step (`object.expand`).
- **Gradient options for type in Expand:** the Expand dialog enables its gradient options for type, symbol art included, only when the outline of at least one character, ruby character, underline or strikethrough gets a gradient that Fill turns into art. A gradient that repeats or reflects in more than 256 runs across a character's outline, VectorCraft's own limit, stays a gradient after Expand (`object.expand.info`, `crates/engine/src/tests/objexpand.rs`).
- **Expand with Alt (Option):** choosing Object › Expand… in the in-window menu bar with Alt (Option on macOS) held expands the selection at once, in one undo step, with the choices OK last expanded with in the Expand dialog ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-objects/arrange-objects/expand-objects.html) describes this shortcut for a gradient), and the dialog opens on those choices. VectorCraft's own rules: the shortcut applies to every expandable selection, the choices are kept until the app quits, the dialog's defaults apply before the first OK, and when none of the choices has something to expand in the selection the dialog opens instead (`ui.expandDialog`'s `immediate`).
- **Type with transparency or effects:** type at less than 100% opacity, in a blend mode other than Normal, or with raster effects such as a drop shadow keeps its glyph outlines between frames, as opaque type does, and is laid out again when it is edited or the fonts change. At 2880 × 1800 on 8 threads, a page of 1,000 type objects takes 13 ms a frame instead of 23 ms at 80% opacity, 31 ms instead of 41 ms in Multiply and 16 ms instead of 26 ms with a drop shadow, with the same pixels.