From 1f1dc6b7d5563cce1e996245376111db92dd7f77 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 14:49:52 -0800 Subject: [PATCH 01/26] Swatches: New Swatch and Delete Swatch drops carry hidden selected swatches and go by the release A selected swatch dragged onto New Swatch or Delete Swatch now carries every selected swatch of its kind, also those the find field or the kind filter hides, as a click on Delete Swatch does. Both buttons take the drop from the first pointer button released in the frame and from where it was released: a secondary release ends the drag even when the primary release follows in the same frame, a release on the button counts when the pointer leaves it later in the frame, and a release beside the button, or on the button while another window covers it, does not count. --- crates/ui-egui/src/panels/swatches/actions.rs | 63 +++++++--- crates/ui-egui/src/panels/swatches/tests.rs | 119 ++++++++++++++++++ docs/target-app-parity.md | 4 +- 3 files changed, 164 insertions(+), 22 deletions(-) diff --git a/crates/ui-egui/src/panels/swatches/actions.rs b/crates/ui-egui/src/panels/swatches/actions.rs index 1034f6207a..49c34246ee 100644 --- a/crates/ui-egui/src/panels/swatches/actions.rs +++ b/crates/ui-egui/src/panels/swatches/actions.rs @@ -119,31 +119,55 @@ fn dragged_deletable(app: &VectorcraftApp, ctx: &egui::Context) -> Vec { } /// The names of the swatches or color groups of the active document being dragged from the list, -/// in panel order. Empty for any other drag, and for a drag started in another document. +/// in panel order. A row that is part of the panel's selection carries every selected row of its +/// kind (swatches or color groups), also those that the find field or the kind filter hides, as a +/// click on the button takes the whole selection. Empty for any other drag, and for a drag started +/// in another document. fn dragged_rows(app: &VectorcraftApp, ctx: &egui::Context) -> Vec { let Some(st) = app.session.active() else { return vec![] }; if pstate::>(ctx, DRAG_DOC) != Some(st.uid) { return vec![]; } - match egui::DragAndDrop::payload::(ctx).as_deref() { - Some(PanelDrag::Paint { rows: Some(r), .. }) => r.names.clone(), - _ => vec![], + let Some(drag) = egui::DragAndDrop::payload::(ctx) else { return vec![] }; + let PanelDrag::Paint { rows: Some(r), .. } = &*drag else { return vec![] }; + let sel: Vec = pstate(ctx, "swatch-selected"); + if !sel.contains(&r.grabbed) { + return r.names.clone(); } + super::entries(app, Kind::All, "") + .iter() + .filter(|e| e.is_folder() == r.groups && sel.iter().any(|s| s == e.name())) + .map(|e| e.name().to_string()) + .collect() +} + +/// Whether the first pointer button released this frame is the primary one, released over +/// `button` while no other panel or window covers it there. The position of that release counts, +/// not where the pointer is at the end of the frame. +fn primary_released_on(ui: &Ui, button: &Response) -> bool { + let first = ui.input(|i| { + i.events.iter().find_map(|e| match e { + egui::Event::PointerButton { pos, button: b, pressed: false, .. } => Some((*b, *pos)), + _ => None, + }) + }); + first.is_some_and(|(b, pos)| { + b == egui::PointerButton::Primary && button.interact_rect.contains(pos) && ui.ctx().layer_id_at(pos).is_none_or(|l| l == button.layer_id) + }) } /// Swatches or color groups (`names`) dragged onto Delete Swatch (`button`): the button is -/// outlined while they are held over it, and the release of the primary button asks to delete them -/// as a plain click does ([`delete`]); Alt does not skip the question. The release of another -/// button ends the drag, and other drags are left to their own targets. +/// outlined while they are held over it, and the release of the primary button on it asks to +/// delete them as a plain click does ([`delete`]); Alt does not skip the question. The release of +/// another button first ends the drag, and other drags are left to their own targets. fn drop_on_delete(app: &mut VectorcraftApp, ui: &Ui, button: &Response, names: Vec) { - if names.is_empty() || button.dnd_hover_payload::().is_none() { + if names.is_empty() { return; } - widgets::drop_target_outline(ui, button.rect); - if !ui.input(|i| i.pointer.button_released(egui::PointerButton::Primary)) { - return; + if button.dnd_hover_payload::().is_some() { + widgets::drop_target_outline(ui, button.rect); } - if button.dnd_release_payload::().is_some() { + if primary_released_on(ui, button) && egui::DragAndDrop::take_payload::(ui.ctx()).is_some() { delete(app, names, false); } } @@ -157,18 +181,17 @@ fn dragged_swatches(app: &VectorcraftApp, ctx: &egui::Context) -> Vec { } /// Swatches (`names`) dragged onto New Swatch (`button`): the button is outlined while they are -/// held over it, and the release of the primary button duplicates them ([`duplicate`]), whatever -/// modifiers are held. The release of another button ends the drag, and other drags are left to -/// their own targets. +/// held over it, and the release of the primary button on it duplicates them ([`duplicate`]), +/// whatever modifiers are held. The release of another button first ends the drag, and other drags +/// are left to their own targets. fn drop_on_new(app: &mut VectorcraftApp, ui: &Ui, button: &Response, names: Vec) { - if names.is_empty() || button.dnd_hover_payload::().is_none() { + if names.is_empty() { return; } - widgets::drop_target_outline(ui, button.rect); - if !ui.input(|i| i.pointer.button_released(egui::PointerButton::Primary)) { - return; + if button.dnd_hover_payload::().is_some() { + widgets::drop_target_outline(ui, button.rect); } - if button.dnd_release_payload::().is_some() { + if primary_released_on(ui, button) && egui::DragAndDrop::take_payload::(ui.ctx()).is_some() { duplicate(app, ui.ctx(), &names); } } diff --git a/crates/ui-egui/src/panels/swatches/tests.rs b/crates/ui-egui/src/panels/swatches/tests.rs index 56e6b664b1..c5d634eab3 100644 --- a/crates/ui-egui/src/panels/swatches/tests.rs +++ b/crates/ui-egui/src/panels/swatches/tests.rs @@ -1001,6 +1001,125 @@ fn new_swatch_ignores_other_drags() { assert!(app.ui.dialog.is_some(), "a click opens the New Swatch dialog"); } +/// A selected swatch dragged onto New Swatch or Delete Swatch carries the selected swatches that +/// the find field hides, as a click on Delete Swatch takes them too. The copies are selected in +/// panel order. +#[test] +fn footer_drops_carry_selected_swatches_that_find_hides() { + let mut app = app(); + let ctx = context(); + set_pstate(&ctx, "swatch-show-find", true); + ctx.data_mut(|d| d.insert_temp(find_id(), "Orange".to_string())); + let sel = || ["Lime", "Orange"].map(String::from).to_vec(); + let order = names_of(&app, None); + let at = |n: &str| order.iter().position(|x| x == n).unwrap_or_else(|| panic!("no swatch {n}")); + let mut copies = vec![("Lime", "Lime copy"), ("Orange", "Orange copy")]; + copies.sort_by_key(|(n, _)| at(n)); + let copies: Vec<&str> = copies.into_iter().map(|(_, c)| c).collect(); + set_pstate(&ctx, "swatch-selected", sel()); + let undo = undo_steps(&app); + assert_eq!(drag_to_button(&mut app, &ctx, "Orange", "New Swatch", Modifiers::NONE, 1.0), (true, true)); + let d = app.session.doc().unwrap().doc.clone(); + assert!(d.swatch("Orange copy").is_some() && d.swatch("Lime copy").is_some(), "the hidden selected swatch is duplicated too"); + assert_eq!(selected(&ctx), copies, "both copies are selected, in panel order"); + assert_eq!(undo_steps(&app), undo + 1, "one undo step for both"); + set_pstate(&ctx, "swatch-selected", sel()); + assert_eq!(drag_to_trash(&mut app, &ctx, "Orange", Modifiers::NONE, 2.0), (true, true)); + assert_eq!(dialog_message(&app).as_deref(), Some("Delete these 2 swatches and groups?"), "the hidden selected swatch is deleted too"); + crate::dialogs::confirm(&mut app).unwrap(); + let d = app.session.doc().unwrap().doc.clone(); + assert!(d.swatch("Orange").is_none() && d.swatch("Lime").is_none(), "both are deleted"); +} + +/// Drag the tile of `name` until it is held over the footer button labeled `label`, a frame per +/// step from `time`, and return the button. +fn hold_over_button(app: &mut VectorcraftApp, ctx: &egui::Context, name: &str, label: &str, time: f64) -> Rect { + frame_out(app, ctx, vec![], Modifiers::NONE, time); + let (target, _) = footer_button(&frame_out(app, ctx, vec![], Modifiers::NONE, time + 0.05), label); + let from = tile_center(ctx, name); + let press = Event::PointerButton { pos: from, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE }; + frame_out(app, ctx, vec![Event::PointerMoved(from), press], Modifiers::NONE, time + 0.1); + frame_out(app, ctx, vec![Event::PointerMoved(from + vec2(6.0, 4.0))], Modifiers::NONE, time + 0.2); + frame_out(app, ctx, vec![Event::PointerMoved(target.center())], Modifiers::NONE, time + 0.3); + let held = frame_out(app, ctx, vec![Event::PointerMoved(target.center())], Modifiers::NONE, time + 0.4); + assert!(outlined(&held, target), "{name} is held over {label}"); + target +} + +/// One frame of the panel with a window drawn over `cover`. +fn frame_covered(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec, time: f64, cover: Rect) { + let screen_rect = Some(Rect::from_min_size(Pos2::ZERO, vec2(280.0, 700.0))); + let events = std::iter::once(Event::ModifiersChanged(Modifiers::NONE)).chain(events).collect(); + let input = egui::RawInput { events, time: Some(time), screen_rect, ..Default::default() }; + let mut out = ctx.run_ui(input, |ui| { + show(app, ui); + egui::Area::new(egui::Id::unique("swatch-test-cover")).order(egui::Order::Foreground).fixed_pos(cover.min).show(ui.ctx(), |ui| { + ui.allocate_exact_size(cover.size(), Sense::hover()); + }); + }); + out.textures_delta.clear(); +} + +/// New Swatch and Delete Swatch go by the first button released in a frame and by where it was +/// released: a secondary release followed by the primary release in one frame ends the drag +/// without a drop, a primary release on the button drops even when the pointer leaves the button +/// later in that frame, and a primary release beside the button, or on the button while a window +/// covers it, does not drop. +#[test] +fn footer_drops_go_by_the_first_release_and_where_it_happened() { + let mut app = app(); + let ctx = context(); + let out = frame_out(&mut app, &ctx, vec![], Modifiers::NONE, 0.0); + let (options, group) = (footer_button(&out, "Swatch Options").0, footer_button(&out, "New Color Group").0); + let beside = pos2((options.right() + group.left()) / 2.0, group.center().y); + let press = |at, button, pressed| Event::PointerButton { pos: at, button, pressed, modifiers: Modifiers::NONE }; + for (i, label) in ["New Swatch", "Delete Swatch"].into_iter().enumerate() { + let t = 10.0 * i as f64; + let (before, undo) = (app.session.doc().unwrap().doc.clone(), undo_steps(&app)); + let unchanged = |app: &VectorcraftApp, case: &str| { + assert!(app.ui.dialog.is_none(), "{label}, {case}: no dialog"); + assert_eq!(app.session.doc().unwrap().doc, before, "{label}, {case}: unchanged"); + assert_eq!(undo_steps(app), undo, "{label}, {case}: no undo step"); + }; + // A secondary release, then the primary release, in one frame. + let button = hold_over_button(&mut app, &ctx, "Orange", label, t + 1.0); + frame_out(&mut app, &ctx, vec![press(button.center(), PointerButton::Secondary, true)], Modifiers::NONE, t + 1.5); + let both = vec![press(button.center(), PointerButton::Secondary, false), press(button.center(), PointerButton::Primary, false)]; + frame_out(&mut app, &ctx, both, Modifiers::NONE, t + 1.6); + // egui counts the secondary press on the button and the primary release as a click on the + // button, so New Swatch opens its dialog; the drop itself asks nothing and duplicates nothing. + let kind = app.ui.dialog.take().map(|d| d.kind); + assert_ne!(kind.as_deref(), Some(crate::dialogs::confirm::KIND), "{label}: a secondary release first does not ask"); + unchanged(&app, "a secondary release first"); + // A primary release beside the button, then the pointer on the button, in one frame. + let button = hold_over_button(&mut app, &ctx, "Orange", label, t + 2.0); + let late = vec![Event::PointerMoved(beside), press(beside, PointerButton::Primary, false), Event::PointerMoved(button.center())]; + frame_out(&mut app, &ctx, late, Modifiers::NONE, t + 2.5); + unchanged(&app, "a release beside the button"); + // A primary release on the button while a window covers it. + let button = hold_over_button(&mut app, &ctx, "Orange", label, t + 2.6); + // A new window shows from its second frame. + for dt in [3.02, 3.05] { + frame_covered(&mut app, &ctx, vec![Event::PointerMoved(button.center())], t + dt, button); + } + frame_covered(&mut app, &ctx, vec![press(button.center(), PointerButton::Primary, false)], t + 3.1, button); + unchanged(&app, "a release on a covered button"); + // A primary release on the button, then the pointer beside it, in one frame. + let button = hold_over_button(&mut app, &ctx, "Orange", label, t + 4.0); + let early = vec![press(button.center(), PointerButton::Primary, false), Event::PointerMoved(beside)]; + frame_out(&mut app, &ctx, early, Modifiers::NONE, t + 4.5); + if label == "New Swatch" { + assert!(app.session.doc().unwrap().doc.swatch("Orange copy").is_some(), "{label}: a release on the button duplicates"); + assert_eq!(undo_steps(&app), undo + 1, "{label}: one undo step"); + app.run("edit.undo", json!({})).unwrap(); + } else { + assert_eq!(dialog_message(&app).as_deref(), Some("Delete “Orange”?"), "{label}: a release on the button asks"); + crate::dialogs::cancel(&mut app); + } + unchanged(&app, "after the drop is undone or canceled"); + } +} + #[test] fn art_dropped_on_the_panel_becomes_a_pattern_swatch() { let mut app = app(); diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 641d87bdcc..b9e6871630 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1863,8 +1863,8 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur Right-clicking a swatch in either list or thumbnail view selects it without applying paint and offers Swatch Options…, Duplicate Swatch and Delete Swatch for that item. None, [Registration] and missing swatches disable these actions. Existing active-item multiselection is retained; actions still target only the clicked item. Evidence: `panels::swatches::tests::context_menu` harness tests cover all five views, selection, dialog dispatch, duplicate/delete and Undo. All 39 Swatches tests pass; the regression fails with the menu hooks removed. Rendered headless list and thumbnail menus were inspected, and a fresh local deep CodeRabbit review reported zero findings. Full workspace CI passed on Linux/WSL on the merged branch (all 13 gates), including the test-helper correction for the upstream compile error tracked in #7727; native Windows full CI has two unchanged engine-test failures. Scores and estimates unchanged. Validation on 2026-11-15: native Windows formatting, workspace Clippy and all 39 focused Swatches tests passed. Windows full CI stopped at unchanged engine tests `tests::package::a_confined_package_names_files_outside_the_read_root_by_name` (slash-sensitive report assertion) and `tests::plugins::plugin_storage_behind_a_link_is_left_alone` (storage-link setup returned AlreadyExists). Both cases pass in the Linux/WSL full CI run, which passed all 13 gates. No engine or CI workflow changes are included. The panel's Delete Swatch and Swatch Options (footer buttons and panel menu), New Color Group and Save Swatch Library treat only None and [Registration] as reserved, so a user swatch or color group whose name starts with `[` can be deleted, edited, grouped and saved; selected names the document no longer holds are left out (`panels::swatches::tests::bracketed_user_swatches_and_groups_can_be_deleted_and_edited`). - Dragging swatches onto Delete Swatch deletes them ([the help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=136), Replace, merge, or delete swatches section, lists this drag as one of the ways to delete the selected swatches): a swatch or color group dragged from the Swatches panel, in any view, and released on the Delete Swatch button is deleted through `swatch.delete`, even while nothing was selected and the button is disabled for clicks. A swatch that is part of the selection carries the other selected swatches of its kind with it. VectorCraft's own rules: the drop asks first as a plain click does, and Alt does not skip the question; Cancel keeps everything, and OK deletes them in one undo step; None and [Registration] are never taken; the button is enabled while swatches are selected or while a swatch or group of the active document is being dragged, and it is outlined only while such a swatch or group is held over it, so a paint from another panel, art and a swatch dragged from another document delete nothing. Tests: `panels::swatches::tests::swatches_dropped_on_delete_swatch_are_deleted_after_asking`, `delete_swatch_ignores_other_drags`. - Dragging swatches onto New Swatch duplicates them ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-colors/use-swatches/duplicate-swatches.html) gives this drag as another way to duplicate the selected swatches): a swatch dragged from the Swatches panel, in any view, and released on the New Swatch button is copied through `swatch.duplicate` without opening the New Swatch dialog. A swatch that is part of the selection carries the other selected swatches with it. VectorCraft's own rules: each copy goes just after its swatch and in its color group, named ` copy` and then ` copy 2`; the copies of one drop are one undo step and are selected; modifiers held on release do not change the drop; color groups, None and [Registration] are not duplicated; the button is outlined only while such a swatch of the active document is held over it, so a paint from another panel, art, a swatch dragged from another document and a swatch deleted during the drag duplicate nothing. Tests: `panels::swatches::tests::swatches_dropped_on_new_swatch_are_duplicated`, `new_swatch_ignores_other_drags`. + Dragging swatches onto Delete Swatch deletes them ([the help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=136), Replace, merge, or delete swatches section, lists this drag as one of the ways to delete the selected swatches): a swatch or color group dragged from the Swatches panel, in any view, and released on the Delete Swatch button is deleted through `swatch.delete`, even while nothing was selected and the button is disabled for clicks. A swatch that is part of the selection carries the other selected swatches of its kind with it, also those the find field or the kind filter hides. VectorCraft's own rules: the drop asks first as a plain click does, and Alt does not skip the question; Cancel keeps everything, and OK deletes them in one undo step; None and [Registration] are never taken; the drop counts only when the first button released is the primary one and it is released on the button; the button is enabled while swatches are selected or while a swatch or group of the active document is being dragged, and it is outlined only while such a swatch or group is held over it, so a paint from another panel, art and a swatch dragged from another document delete nothing. Tests: `panels::swatches::tests::swatches_dropped_on_delete_swatch_are_deleted_after_asking`, `delete_swatch_ignores_other_drags`. + Dragging swatches onto New Swatch duplicates them ([the help page](https://helpx.adobe.com/illustrator/desktop/manage-colors/use-swatches/duplicate-swatches.html) gives this drag as another way to duplicate the selected swatches): a swatch dragged from the Swatches panel, in any view, and released on the New Swatch button is copied through `swatch.duplicate` without opening the New Swatch dialog. A swatch that is part of the selection carries the other selected swatches with it, also those the find field or the kind filter hides. VectorCraft's own rules: each copy goes just after its swatch and in its color group, named ` copy` and then ` copy 2`; the copies of one drop are one undo step and are selected in panel order; modifiers held on release do not change the drop; the drop counts only when the first button released is the primary one and it is released on the button; color groups, None and [Registration] are not duplicated; the button is outlined only while such a swatch of the active document is held over it, so a paint from another panel, art, a swatch dragged from another document and a swatch deleted during the drag duplicate nothing. Tests: `panels::swatches::tests::swatches_dropped_on_new_swatch_are_duplicated`, `new_swatch_ignores_other_drags`, `footer_drops_carry_selected_swatches_that_find_hides`, `footer_drops_go_by_the_first_release_and_where_it_happened`. Editing, renaming, deleting or merging a global swatch also changes the colors linked to it in graph designs, the art of brushes and the tile that pattern editing's Cancel puts back, in the same undo step as the rest of the art; Default Swatches with replace unlinks them there too. A swatch step in `command.batch` (Delete, Swatch Options, Merge, Edit Color Group) changes the fill and stroke for new art as the command run on its own does, so art drawn later in the batch or after it takes the same paint; a batch that fails, and a canceled batch preview, put back the paints it started with, and a canceled Swatch Options preview leaves them as they were. These swatch commands also change the fills and strokes of the appearance new art takes, and Undo and Redo of the command or the batch put the paints for new art back with the swatches. Spot Colors options (`swatch.spotOptions`) and Default Swatches with replace (`swatch.resetDefaults {replace: true}`) as `command.batch` steps also change the fill and stroke for new art as each command run on its own does: a fill or stroke linked to a Lab spot swatch keeps its link and tint and takes the Lab values or their CMYK equivalent, and one linked to a swatch the replace removes keeps its color and loses the link. Evidence: `swatch_steps_in_a_batch_change_the_new_art_paints_as_commands_do`, `spot_colors_options_in_a_batch_change_the_new_art_paints_as_the_command_does`, `default_swatches_replace_in_a_batch_unlinks_the_new_art_paints_as_the_command_does`, `undo_and_redo_of_a_swatch_edit_put_back_the_new_art_paints`, `swatch_edits_reach_the_paints_of_the_new_art_template`, `a_failed_batch_puts_back_the_new_art_paints_a_swatch_step_changed` and `canceling_a_swatch_options_preview_keeps_the_new_art_paints` in `crates/engine/src/tests/swatches.rs`. Add Used Colors (`swatch.addUsedColors`) and Select All Unused (`swatch.unused`) look colors, swatch names, links, tints and gradients up in hash sets instead of searching every swatch and color for each color or linked paint (New Color Group from artwork too), and New Swatch with several colors (`swatch.new`), New Color Group (`swatch.newGroup`) and Edit Color Group (`swatch.editGroup`) name their new swatches from one set of the names already taken. The new swatches keep their names, order and links, and Select All Unused lists the same swatches. Evidence: `add_used_colors_adds_each_new_color_once_with_free_names`, `add_used_colors_global_links_every_paint_of_a_new_color`, `unused_matches_links_tints_colors_gradients_and_patterns_exactly`, `new_swatches_from_colors_are_numbered_after_names_already_taken`, `new_color_group_numbers_its_colors_after_the_group_and_its_moved_swatches`, `new_color_group_from_artwork_lists_each_color_once_with_free_names` and `edit_color_group_numbers_extra_colors_after_the_names_it_keeps` in `crates/engine/src/tests/swatchcmds.rs`; `free_swatch_names_match_naming_each_swatch_as_it_is_added` and `free_swatch_names_match_new_swatch_names_as_swatches_are_added` in `crates/doc/src/swatches.rs`. From 73bd88227afbb33982d2cdc08073747e573db16e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 16:10:33 -0800 Subject: [PATCH 02/26] Docs: UI chrome row records the Swatches footer drop rules --- docs/target-app-parity.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index bbc7885714..cf806082ac 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -297,7 +297,7 @@ dominate; 3D, graphs and automation are specialist). They sum to 105. Feature de | Export for Screens, Asset Export, slices, Save for Web | 3 | 85% | anti-aliasing ghost borders (#983); TIFF choices and settings are implemented | 2–4 | estimated | | Print, colour management, separations, flattener | 3 | 80% | Production Preflight available; print preview fidelity remains | 2–4 | estimated | | Automation (Actions, Variables, scripting, batch) | 3 | 60% | a scripting surface (Illustrator: JavaScript/ExtendScript), Batch, image and graph variables, dataset import/export | 8–14 | estimated; MCP `add_text` exposes existing vertical type; score and hours unchanged | -| UI chrome (panels, Properties, workspaces, preferences) | 6 | 80% | Properties per context, 2 Preferences options stored but unused (#394, audited 2026-10-30: Scratch Disks, legacy vector clipboard), context menus in the panels that have none, accessibility | 13–20 | estimated; floating panels in OS windows of their own on the desktop (#4135), score and hours unchanged; macOS save Format menu implemented (#866), score and hours unchanged; Eyedropper cursor and precise setting checked (#1269), OS visual QA unverified; the line under the Preferences fields describes each General, Selection & Anchor Display, Guides & Grid, Smart Guides and Slices setting on hover and keyboard focus (#8199, #8223, #8248, #8264, #8360), score and hours unchanged; numeric-field focus and normal text drags regression-tested (#1326); a focus click released more than 1 pt from its press keeps the caret and a tap within 1 pt selects all (#6659); artboard navigation synchronizes the tool selection before destructive actions; status messages and readouts use stable responsive allocations sized for localized labels and ordinary coordinates (sample widths cached by language/unit/DPI; regression and contributor original-file evidence below; scores/hours unchanged); effect dialogs' colour fields show a swatch that opens the Color Picker (#5365), score and hours unchanged; icon-strip flyouts retain user sizes (#5713); floating tab groups collapse into the side icon rail and opened rail panels fold back into it (#5925, in part), scores and hours unchanged ; interim macOS cursor delivery (#2292), headless coverage only; native validation pending, score and hours unchanged; Swatches item context menus have focused regressions and rendered-layout evidence below; scores and estimates unchanged | +| UI chrome (panels, Properties, workspaces, preferences) | 6 | 80% | Properties per context, 2 Preferences options stored but unused (#394, audited 2026-10-30: Scratch Disks, legacy vector clipboard), context menus in the panels that have none, accessibility | 13–20 | estimated; floating panels in OS windows of their own on the desktop (#4135), score and hours unchanged; macOS save Format menu implemented (#866), score and hours unchanged; Eyedropper cursor and precise setting checked (#1269), OS visual QA unverified; the line under the Preferences fields describes each General, Selection & Anchor Display, Guides & Grid, Smart Guides and Slices setting on hover and keyboard focus (#8199, #8223, #8248, #8264, #8360), score and hours unchanged; numeric-field focus and normal text drags regression-tested (#1326); a focus click released more than 1 pt from its press keeps the caret and a tap within 1 pt selects all (#6659); artboard navigation synchronizes the tool selection before destructive actions; status messages and readouts use stable responsive allocations sized for localized labels and ordinary coordinates (sample widths cached by language/unit/DPI; regression and contributor original-file evidence below; scores/hours unchanged); effect dialogs' colour fields show a swatch that opens the Color Picker (#5365), score and hours unchanged; icon-strip flyouts retain user sizes (#5713); floating tab groups collapse into the side icon rail and opened rail panels fold back into it (#5925, in part), scores and hours unchanged ; interim macOS cursor delivery (#2292), headless coverage only; native validation pending, score and hours unchanged; Swatches item context menus have focused regressions and rendered-layout evidence below; swatches dropped on New Swatch or Delete Swatch carry the selected swatches the find field or kind filter hides, and the drop counts only when the first button released is the primary one, released on the button (#8620); scores and estimates unchanged | | Libraries, Links, Package | 2 | 82% | shared libraries, linked graphics, gradients and patterns as library items (no cloud by design) | 2–3 | estimated | | Generative AI (Text to Vector, Generative Recolor, Shape Fill, Concept to Vector, Prompt to Edit, Rewrite Text) | 2 | 0% | a pluggable provider and the panels; needs an owner decision on models | 30–60 | measured (absent) | | **Feature depth** | **105** | **~75%** | | **~250–420** | | From 2b21c1248f974c27a8ba4b497843d12642c2318d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 15:23:40 -0800 Subject: [PATCH 03/26] Fields: number fields outside the shared widgets read field arithmetic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Contour bar's distance, Graph Data's Number of Decimals and Column Width, Map Art's surface number, the Keyboard Shortcuts dialog's Hold Shortcut Delay, the unitless values of the 3D effect dialogs and the number fields of Character Style Options read typed text with their own readers, so `4x3` or `1+2` were not read in most of them. They now read it with the shared field arithmetic. The Contour bar's distance and Character Style Options' length fields also read a unit (`2 mm`). Warichu Settings' Lines and Scale read text given through `ui.dialog.set` the same way. These fields take `%` and `°` only where they show them, and none of them reads an exponent (`1e3`) or a space inside a number (`1 000`). In the shared unitless fields, a unit suffix, `%` or `°` between two digits is now refused: `1%2` read as 12. The Stroke panel's Limit reads `2x3` as 6 instead of 23. Docs: docs/mcp.md, docs/target-app-parity.md. --- crates/ui-egui/src/canvas/contour_bar.rs | 6 +- crates/ui-egui/src/canvas/tests.rs | 40 +++++++++++++ .../ui-egui/src/dialogs/char_style_options.rs | 31 +++++++++- crates/ui-egui/src/dialogs/graph_data.rs | 59 ++++++++++++++++++- crates/ui-egui/src/dialogs/revolve.rs | 16 +++-- crates/ui-egui/src/dialogs/revolve/tests.rs | 13 ++++ .../ui-egui/src/dialogs/tests_track_cube.rs | 37 ++++++++++++ crates/ui-egui/src/dialogs/three_d_classic.rs | 3 +- crates/ui-egui/src/dialogs/warichu.rs | 31 ++++++++-- crates/ui-egui/src/shortcut_editor.rs | 42 ++++++++++++- crates/ui-egui/src/widgets.rs | 43 +++++++++++++- crates/ui-egui/src/widgets/numeric.rs | 46 ++++++++++++++- docs/mcp.md | 8 ++- docs/target-app-parity.md | 1 + 14 files changed, 353 insertions(+), 23 deletions(-) diff --git a/crates/ui-egui/src/canvas/contour_bar.rs b/crates/ui-egui/src/canvas/contour_bar.rs index 4b560eeba6..f01a916738 100644 --- a/crates/ui-egui/src/canvas/contour_bar.rs +++ b/crates/ui-egui/src/canvas/contour_bar.rs @@ -88,10 +88,12 @@ pub(super) fn contour_bar(app: &mut VectorcraftApp, ui: &mut Ui, xf: &Xf) { ui.horizontal(|ui| { ui.spacing_mut().item_spacing.x = 6.0; ui.label(egui::RichText::new(tl!("Contour")).color(t.text_strong)); - // The distance: a drag or typed value is applied when it ends, as one step. + // The distance: a drag or typed value is applied when it ends, as one step. Typed + // text reads as a length field's does (`4x3`, `2 mm`). let key = egui::Id::unique("contour-bar-offset"); let mut v = ui.data(|d| d.get_temp::(key)).unwrap_or(shown); - let resp = ui.add(egui::DragValue::new(&mut v).speed(0.5).range(-1e5..=1e5).suffix(" pt")); + let resp = + ui.add(egui::DragValue::new(&mut v).speed(0.5).range(-1e5..=1e5).suffix(" pt").custom_parser(crate::widgets::typed_points)); if resp.dragged() || resp.has_focus() { ui.data_mut(|d| d.insert_temp(key, v)); } diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index d5244aa234..cb85ce653e 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -14332,6 +14332,46 @@ fn the_contour_bar_sets_corners_and_bakes() { assert!(offsets(&app).is_empty(), "baked"); } +/// The Contour bar's distance reads typed text as a length field does: `4x3` is 12 pt, `2 mm` is +/// 2 mm and `−3` (a minus sign) is -3 pt, applied when Enter ends the typing. +#[test] +fn the_contour_bar_distance_takes_field_arithmetic() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap(); + app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 80, "height": 60})).unwrap(); + app.select_tool("contour"); + app.session.execute("addon.contour.set", &json!({"offset": 8, "corners": "round"})).unwrap(); + let ctx = egui::Context::default(); + let offset = |app: &VectorcraftApp| { + let mut found = vec![]; + app.session.active().unwrap().doc.walk(|n| { + if let Some(e) = n.appearance.effects.iter().find(|e| e.id == "path.offsetPath") { + found.push(e.params["offset"].as_f64().unwrap_or(f64::NAN)); + } + }); + found + }; + let enter = egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }; + // Text that does not read (`2 qq`) leaves the distance as it was. + let mm = 2.0 * 72.0 / 25.4; + for (typed, want) in [(&["4x3"][..], 12.0), (&["2 mm"], mm), (&["\u{2212}3"], -3.0), (&["2 qq"], -3.0)] { + contour_bar_labels(&mut app, &ctx, vec![]); + let labels = contour_bar_labels(&mut app, &ctx, vec![]); + let at = labels.iter().find(|(t, _)| t.ends_with(" pt")).map(|(_, r)| r.center()).unwrap_or_else(|| panic!("no distance in {labels:?}")); + let button = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; + contour_bar_labels(&mut app, &ctx, vec![egui::Event::PointerMoved(at)]); + contour_bar_labels(&mut app, &ctx, vec![button(true), button(false)]); + contour_bar_labels(&mut app, &ctx, vec![]); + for part in typed { + contour_bar_labels(&mut app, &ctx, vec![egui::Event::Text((*part).into())]); + } + contour_bar_labels(&mut app, &ctx, vec![enter.clone()]); + contour_bar_labels(&mut app, &ctx, vec![]); + let got = offset(&app); + assert!(got.len() == 1 && (got[0] - want).abs() < 1e-6, "{typed:?}: {got:?}"); + } +} + /// A frame the render worker finished for `job`: white pixels of the job's size. fn finished(job: &crate::render_worker::Job) -> crate::render_worker::Done { let img = vectorcraft_render::Rendered { width: job.w, height: job.h, pixels: vec![255; job.w as usize * job.h as usize * 4] }; diff --git a/crates/ui-egui/src/dialogs/char_style_options.rs b/crates/ui-egui/src/dialogs/char_style_options.rs index c07f7af647..cf47c85156 100644 --- a/crates/ui-egui/src/dialogs/char_style_options.rs +++ b/crates/ui-egui/src/dialogs/char_style_options.rs @@ -309,6 +309,18 @@ fn case_from_attrs(attrs: &Map) -> Option<&'static str> { } } +/// The number text typed into number field `key` reads as, with the field arithmetic: a length in +/// points (`2 mm`) for the length fields, `%` only in the percent fields and `°` only in Character +/// Rotation. +fn typed_number(key: &str, text: &str) -> Option { + match key { + "size" | "leading" | "baseline_shift" | "tcyUpDown" | "tcyLeftRight" | "stroke_width" => crate::widgets::typed_points(text), + "h_scale" | "v_scale" | "fill_tint" | "stroke_tint" => crate::widgets::typed_number_with(text, "%"), + "rotation" => crate::widgets::typed_number_with(text, "°"), + _ => crate::widgets::typed_number(text), + } +} + fn optional_number(d: &Dialog, key: &str) -> Result, String> { let label = match key { "size" => tl!("Size"), @@ -338,7 +350,7 @@ fn optional_number(d: &Dialog, key: &str) -> Result, String> { Some(v) => { let n = v .as_f64() - .or_else(|| v.as_str().and_then(|s| s.trim().parse::().ok())) + .or_else(|| v.as_str().and_then(|s| typed_number(key, s))) .filter(|n| n.is_finite()) .ok_or_else(|| format!("{label} must be a number"))?; // Character Style fields use the Character panel's visible ranges. @@ -1472,6 +1484,23 @@ mod tests { } assert!(same > 0, "General draws its content again: {back:?}"); } + + /// The number fields read typed text as other number fields do: `6x2`, `10+4`, `200/2`, `45°`, + /// and a length with its unit. `%` and `°` only where the field takes them, and an exponent + /// is not read. + #[test] + fn number_fields_take_field_arithmetic() { + let fields = json!({"size": "6x2", "tracking": "10+4", "h_scale": "200/2%", "rotation": "45°", "fill_tint": "25*2", "leading": "1 in"}); + let d = Dialog { kind: KIND.into(), fields: fields.as_object().unwrap().clone() }; + for (key, want) in [("size", 12.0), ("tracking", 14.0), ("h_scale", 100.0), ("rotation", 45.0), ("fill_tint", 50.0), ("leading", 72.0)] { + assert_eq!(optional_number(&d, key), Ok(Some(json!(want))), "{key}"); + } + for (key, text) in [("size", "12°"), ("leading", "50%"), ("tracking", "10%"), ("rotation", "45%"), ("h_scale", "1%2"), ("size", "1e3")] { + let d = Dialog { kind: KIND.into(), fields: json!({ key: text }).as_object().unwrap().clone() }; + assert!(optional_number(&d, key).is_err(), "{key} {text}"); + } + } + #[test] fn unchanged_basic_fields_preserve_original_keys() { for attrs in [ diff --git a/crates/ui-egui/src/dialogs/graph_data.rs b/crates/ui-egui/src/dialogs/graph_data.rs index ab46dbd82c..e1a2071108 100644 --- a/crates/ui-egui/src/dialogs/graph_data.rs +++ b/crates/ui-egui/src/dialogs/graph_data.rs @@ -379,14 +379,15 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { dec = on.then_some(2); } let mut n = dec.unwrap_or(2); - if ui.add_enabled(on, egui::DragValue::new(&mut n).range(0..=MAX_DECIMALS)).changed() { + let field = egui::DragValue::new(&mut n).range(0..=MAX_DECIMALS).custom_parser(widgets::typed_number); + if ui.add_enabled(on, field).changed() { dec = Some(n); } d.fields.insert("decimals".into(), json!(dec)); ui.add_space(12.0); widgets::dim_label(ui, tl!("Column Width:")); let mut w = d.fields.get("width").and_then(Value::as_u64).unwrap_or(7); - let r = ui.add(egui::DragValue::new(&mut w).range(0..=MAX_WIDTH)); + let r = ui.add(egui::DragValue::new(&mut w).range(0..=MAX_WIDTH).custom_parser(widgets::typed_number)); // A value entered with Enter sets every column, also when it is the width shown. Leaving the // field without a new value keeps the columns' own widths. if r.changed() || (r.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter))) { @@ -901,6 +902,60 @@ mod tests { assert_eq!((digits(&app, 1), digits(&app, c), digits(&app, 0)), (7, 7, 7), "Column Width sets every column"); } + /// Cell Style's Number of Decimals and Column Width read typed text as other number fields do: + /// `1+2` is 3 decimals and `4x3` is 12 digits. + #[test] + fn cell_style_fields_take_field_arithmetic() { + let (mut app, _) = app_with("a,b\n1,2", "column"); + open(&mut app).unwrap(); + app.ui.dialog.as_mut().unwrap().fields.insert("decimals".into(), json!(2)); + let ctx = egui::Context::default(); + ctx.enable_accesskit(); + crate::theme::install_fonts(&ctx); + let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1280.0, 900.0)); + let frame = |app: &mut VectorcraftApp, events: Vec| { + let mut out = + ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events, ..Default::default() }, |ui| super::super::show(app, ui.ctx())); + out.textures_delta.clear(); + out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default() + }; + let button = + |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; + let enter = egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }; + for _ in 0..3 { + frame(&mut app, vec![]); + } + // The spin button right of the label `name`. + let field_after = |app: &mut VectorcraftApp, name: &str| { + let nodes = frame(app, vec![]); + let label = nodes + .iter() + .find(|(_, n)| n.role() == egui::accesskit::Role::Label && n.value() == Some(name)) + .and_then(|(_, n)| n.bounds()) + .unwrap_or_else(|| panic!("the {name} label is drawn")); + let field = nodes + .iter() + .filter(|(_, n)| n.role() == egui::accesskit::Role::SpinButton) + .filter_map(|(_, n)| n.bounds()) + .filter(|b| b.x0 >= label.x1 && b.y0 < label.y1 && b.y1 > label.y0) + .min_by(|a, b| a.x0.total_cmp(&b.x0)) + .unwrap_or_else(|| panic!("the {name} field is drawn")); + egui::pos2(((field.x0 + field.x1) / 2.0) as f32, ((field.y0 + field.y1) / 2.0) as f32) + }; + for (name, typed) in [("Number of Decimals:", "1+2"), ("Column Width:", "4x3")] { + let at = field_after(&mut app, name); + frame(&mut app, vec![egui::Event::PointerMoved(at), button(at, true)]); + frame(&mut app, vec![button(at, false)]); + frame(&mut app, vec![]); + frame(&mut app, vec![egui::Event::Text(typed.into())]); + frame(&mut app, vec![enter.clone()]); + frame(&mut app, vec![]); + } + let d = app.ui.dialog.as_ref().unwrap(); + assert_eq!(d.fields.get("decimals"), Some(&json!(3)), "1+2 decimals"); + assert_eq!((col_digits(d, 0), col_digits(d, 1)), (12, 12), "4x3 digits for every column"); + } + #[test] fn a_column_width_in_points_maps_to_whole_digits() { for n in 0..=MAX_WIDTH { diff --git a/crates/ui-egui/src/dialogs/revolve.rs b/crates/ui-egui/src/dialogs/revolve.rs index 568acdb121..eed2c1d33a 100644 --- a/crates/ui-egui/src/dialogs/revolve.rs +++ b/crates/ui-egui/src/dialogs/revolve.rs @@ -739,6 +739,15 @@ fn rail_width(ui: &egui::Ui) -> f32 { (ui.available_width() - VALUE_W - 24.0 - 18.0).clamp(40.0, 134.0) } +/// The value text typed into a [`number`] field showing `suffix` reads as: a length in `unit` (read +/// in the `typed` unit when one is given), otherwise a number with the field arithmetic. +fn typed_value(text: &str, suffix: &str, unit: Option, typed: Option) -> Option { + match unit { + Some(u) => typed.unwrap_or(u).parse(text).map(|v| u.from_pt(v)), + None => widgets::typed_number_with(text, suffix), + } +} + /// A value can be typed, dragged, scrubbed by its label, or moved on its slider. #[allow(clippy::too_many_arguments)] pub(super) fn number(ui: &mut egui::Ui, d: &mut Dialog, key: &str, name: &str, range: (f64, f64), suffix: &str, decimals: usize, unit: Option) { @@ -770,12 +779,7 @@ pub(super) fn number(ui: &mut egui::Ui, d: &mut Dialog, key: &str, name: &str, r .max_decimals(decimals) .suffix(&suffix) .update_while_editing(false) - .custom_parser(|s| { - unit.map_or_else( - || vectorcraft_doc::parse_number(&s.replace(['°', '%'], "")), - |u| typed.unwrap_or(u).parse(s).map(|v| u.from_pt(v)), - ) - }), + .custom_parser(|s| typed_value(s, &suffix, unit, typed)), ) }) .inner; diff --git a/crates/ui-egui/src/dialogs/revolve/tests.rs b/crates/ui-egui/src/dialogs/revolve/tests.rs index dd5f05ad5d..23a6e852b1 100644 --- a/crates/ui-egui/src/dialogs/revolve/tests.rs +++ b/crates/ui-egui/src/dialogs/revolve/tests.rs @@ -903,3 +903,16 @@ fn lighting_presets_cancel_restores_an_existing_custom_light_rig() { dialogs::cancel(&mut h.app); assert_eq!(h.app.session.doc().unwrap().doc, before); } + +/// Unitless values read typed text as other number fields do; the field's `°` or `%` only after an +/// operand, never between two digits. +#[test] +fn typed_values_take_field_arithmetic() { + for (text, suffix, want) in [("45*2", "°", 90.0), ("45x2°", "°", 90.0), ("12,5", "", 12.5), ("50%", "%", 50.0), ("\u{2212}30", "°", -30.0)] { + assert_eq!(typed_value(text, suffix, None, None), Some(want), "{text}"); + } + for (text, suffix) in [("1%2", "%"), ("4°5", "°"), ("8%", ""), ("30%", "°")] { + assert_eq!(typed_value(text, suffix, None, None), None, "{text}"); + } + assert_eq!(typed_value("1 in", " pt", Some(Unit::Points), None), Some(72.0)); +} diff --git a/crates/ui-egui/src/dialogs/tests_track_cube.rs b/crates/ui-egui/src/dialogs/tests_track_cube.rs index 9e36fb89f0..d1cd116c47 100644 --- a/crates/ui-egui/src/dialogs/tests_track_cube.rs +++ b/crates/ui-egui/src/dialogs/tests_track_cube.rs @@ -216,3 +216,40 @@ fn map_art_surfaces_follow_the_active_document() { assert_ne!(first, second, "the two objects' solids differ in size"); assert_eq!(Some(first.as_ref()), own.as_ref(), "the first document's surfaces"); } + +/// Map Art's surface number reads typed text as other number fields do: `1+2` shows surface 3. +#[test] +fn the_map_art_surface_field_takes_field_arithmetic() { + let mut app = crate::VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width":300,"height":300})).unwrap(); + app.run("path.create", json!({"d": "M50 50L150 50L150 150L50 150Z"})).unwrap(); + app.run("effect.dialog", json!({"effect":CLASSIC_EXTRUDE,"item":null})).unwrap(); + let mut d = app.ui.dialog.take().unwrap(); + let ctx = egui::Context::default(); + ctx.enable_accesskit(); + crate::theme::install_fonts(&ctx); + assert!(surfaces(&app, &ctx, &d).unwrap().len() >= 3, "the extruded square has at least 3 surfaces"); + let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0)); + let frame = |d: &mut Dialog, events: Vec| { + let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events, ..Default::default() }, |ui| map_art_controls(&app, ui, d)); + out.textures_delta.clear(); + out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default() + }; + frame(&mut d, vec![]); + let nodes = frame(&mut d, vec![]); + let field = nodes + .iter() + .find(|(_, n)| n.role() == egui::accesskit::Role::SpinButton && n.label() == Some("Surface")) + .and_then(|(_, n)| n.bounds()) + .expect("the Surface field is drawn"); + let at = pos2(((field.x0 + field.x1) / 2.0) as f32, ((field.y0 + field.y1) / 2.0) as f32); + let button = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; + let enter = egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }; + frame(&mut d, vec![egui::Event::PointerMoved(at), button(true)]); + frame(&mut d, vec![button(false)]); + frame(&mut d, vec![]); + frame(&mut d, vec![egui::Event::Text("1+2".into())]); + frame(&mut d, vec![enter]); + frame(&mut d, vec![]); + assert_eq!(shown_surface(&d, 99), 3, "1+2 shows surface 3"); +} diff --git a/crates/ui-egui/src/dialogs/three_d_classic.rs b/crates/ui-egui/src/dialogs/three_d_classic.rs index f25251f574..d6049ee230 100644 --- a/crates/ui-egui/src/dialogs/three_d_classic.rs +++ b/crates/ui-egui/src/dialogs/three_d_classic.rs @@ -128,7 +128,8 @@ pub(super) fn map_art_controls(app: &crate::VectorcraftApp, ui: &mut egui::Ui, d next = Some(current - 1); } let mut typed = current; - let field = ui.add_sized([44.0, 24.0], egui::DragValue::new(&mut typed).range(1..=count).speed(0.1)); + let field = egui::DragValue::new(&mut typed).range(1..=count).speed(0.1).custom_parser(crate::widgets::typed_number); + let field = ui.add_sized([44.0, 24.0], field); field.widget_info(|| egui::WidgetInfo::labeled(egui::Role::SpinButton, true, tl!("Surface"))); if field.changed() { next = Some(typed); diff --git a/crates/ui-egui/src/dialogs/warichu.rs b/crates/ui-egui/src/dialogs/warichu.rs index 156d10e596..c9893caff2 100644 --- a/crates/ui-egui/src/dialogs/warichu.rs +++ b/crates/ui-egui/src/dialogs/warichu.rs @@ -111,14 +111,14 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { false } -/// A number field's value: a number, or a string that reads as one (`"3"`, `"40%"`); `None` for a -/// blank field. `Err` names the field when it holds anything else. -fn number(d: &Dialog, key: &str, name: &str) -> Result, String> { +/// A number field's value: a number, or a string that reads as one (`"3"`, `"20*2"`, and `"40%"` +/// when `suffix` is `%`); `None` for a blank field. `Err` names the field when it holds anything else. +fn number(d: &Dialog, key: &str, name: &str, suffix: &str) -> Result, String> { let v = match d.fields.get(key) { None | Some(Value::Null) => return Ok(None), Some(Value::String(s)) if s.trim().is_empty() => return Ok(None), Some(Value::Number(n)) => n.as_f64(), - Some(Value::String(s)) => s.trim().trim_end_matches('%').trim().parse::().ok(), + Some(Value::String(s)) => crate::widgets::typed_number_with(s, suffix), Some(_) => None, }; v.filter(|v| v.is_finite()).map(Some).ok_or_else(|| format!("{name} must be a number")) @@ -135,7 +135,7 @@ fn params(d: &Dialog) -> Result, String> { let unchanged = |key: &str, v: &Value| initial.and_then(|m| m.get(key)) == Some(v); let opened_with = |key: &str, v: f64| initial.and_then(|m| m.get(key)).and_then(Value::as_f64) == Some(v); let mut p = Map::new(); - if let Some(n) = number(d, "warichuLines", "Lines")?.filter(|&n| !opened_with("warichuLines", n)) { + if let Some(n) = number(d, "warichuLines", "Lines", "")?.filter(|&n| !opened_with("warichuLines", n)) { let n = n.round().clamp(f64::from(*WARICHU_LINES.start()), f64::from(*WARICHU_LINES.end())); // Within 1..6 after the clamp, so the cast keeps the value. let v = json!(n as u8); @@ -155,7 +155,7 @@ fn params(d: &Dialog) -> Result, String> { { p.insert("warichuGap".into(), json!(v)); } - if let Some(n) = number(d, "warichuScale", "Scale")?.filter(|&n| !opened_with("warichuScale", n)) { + if let Some(n) = number(d, "warichuScale", "Scale", "%")?.filter(|&n| !opened_with("warichuScale", n)) { let v = n.clamp(*WARICHU_SCALE.start(), *WARICHU_SCALE.end()); if !opened_with("warichuScale", v) { p.insert("warichuScale".into(), json!(v)); @@ -257,6 +257,25 @@ mod tests { assert_eq!(params(&d).unwrap().get("warichuGap"), Some(&json!(MAX_WARICHU_GAP))); } + /// Lines and Scale given as text read as other number fields read it: `1+2` lines and `30x2%`. + #[test] + fn warichu_settings_dialog_reads_field_arithmetic() { + let opened = json!({"warichuLines": 2, "warichuGap": 0.0, "warichuScale": 50.0}); + let mut fields = opened.clone(); + fields[INITIAL] = opened; + let mut d = Dialog::new(KIND, fields); + d.fields.insert("warichuLines".into(), json!("1+2")); + d.fields.insert("warichuScale".into(), json!("30x2%")); + let p = params(&d).unwrap(); + assert_eq!((p.get("warichuLines"), p.get("warichuScale")), (Some(&json!(3)), Some(&json!(60.0)))); + // `%` only in Scale, and neither field reads an exponent or a mark between two digits. + for (key, text) in [("warichuLines", "3%"), ("warichuLines", "1e0"), ("warichuScale", "1%2"), ("warichuScale", "2e1")] { + let mut d = d.clone(); + d.fields.insert(key.into(), json!(text)); + assert!(params(&d).is_err(), "{key} {text}"); + } + } + /// Characters that differ open a blank field; OK leaves that value alone and sets the others. #[test] fn warichu_settings_dialog_leaves_mixed_values_blank() { diff --git a/crates/ui-egui/src/shortcut_editor.rs b/crates/ui-egui/src/shortcut_editor.rs index a9d7b022a7..39cfa6e806 100644 --- a/crates/ui-egui/src/shortcut_editor.rs +++ b/crates/ui-egui/src/shortcut_editor.rs @@ -2320,7 +2320,8 @@ fn hold_row(ui: &mut egui::Ui, t: &Tokens, d: &mut Dialog) { ui.label(egui::RichText::new(tl!("Hold Shortcut Delay")).color(t.text_dim)); let (min, max) = vectorcraft_engine::KEY_HOLD_DELAY_RANGE; let mut delay = dialog_hold_delay(d); - if ui.add(egui::DragValue::new(&mut delay).range(min..=max).speed(0.01).fixed_decimals(2).suffix(" s")).changed() { + let field = egui::DragValue::new(&mut delay).range(min..=max).speed(0.01).fixed_decimals(2).suffix(" s"); + if ui.add(field.custom_parser(|s| crate::widgets::typed_number_with(s, "s"))).changed() { d.fields.insert("keyHoldDelay".into(), json!(delay)); } } @@ -3881,6 +3882,45 @@ mod tests { assert_eq!(app.ui.engine_prefs["keyHoldDelay"], json!(0.5)); } + /// The Hold Shortcut Delay reads typed text as other number fields do, its `s` after any operand: + /// `0.25 s x 2` is half a second. + #[test] + fn the_hold_shortcut_delay_takes_field_arithmetic() { + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + open(&mut app); + app.ui.dialog.as_mut().unwrap().fields.insert("holdShortcuts".into(), json!(true)); + let ctx = egui::Context::default(); + theme::install_fonts(&ctx); + let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1280.0, 900.0)); + let frame = |app: &mut VectorcraftApp, events: Vec| { + let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events, ..Default::default() }, |ui| show(app, ui.ctx())); + out.textures_delta.clear(); + out.shapes + .into_iter() + .filter_map(|c| match c.shape { + egui::Shape::Text(t) => Some((t.galley.text().to_string(), t.visual_bounding_rect())), + _ => None, + }) + .collect::>() + }; + frame(&mut app, vec![]); + let texts = frame(&mut app, vec![]); + let shown = format!("{:.2}", dialog_hold_delay(app.ui.dialog.as_ref().unwrap())); + let at = texts.iter().find(|(t, _)| *t == shown).map(|(_, r)| r.center()).unwrap_or_else(|| panic!("no `{shown}` in {texts:?}")); + let button = + |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; + let enter = egui::Event::Key { key: egui::Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }; + frame(&mut app, vec![egui::Event::PointerMoved(at), button(true)]); + frame(&mut app, vec![button(false)]); + frame(&mut app, vec![]); + frame(&mut app, vec![egui::Event::Text("0.25 s x 2".into())]); + frame(&mut app, vec![enter]); + frame(&mut app, vec![]); + // Enter may also end the dialog with OK, which writes the delay to the preferences. + let delay = app.ui.dialog.as_ref().map_or(app.session.prefs.key_hold_delay, dialog_hold_delay); + assert_eq!(delay, 0.5, "0.25 s x 2"); + } + /// The info button shows how hold shortcuts work. #[test] fn the_info_button_explains_hold_shortcuts() { diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index b67df13c7f..a17d9b0e85 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -62,7 +62,7 @@ pub use dropdowns::{ pub(crate) use dropdowns::{menu_floor, menu_room_either}; pub use labels::{dim_label, dim_name, divider, field_label, label_row, link_label, section_header, section_toggle, section_toggle_name, subheader}; pub(crate) use labels::{dim_label_width, field_panel_label, label_field, take_previous_label, text_width}; -pub(crate) use numeric::{ANY, round_to, set_bare_numbers_are_points, typed_unit}; +pub(crate) use numeric::{ANY, round_to, set_bare_numbers_are_points, typed_number, typed_number_with, typed_points, typed_unit}; pub use numeric::{ SpinPick, mixed_field, mixed_field_named, num_field, num_field_live, num_field_named, num_field_refusing, num_field_within, num_field_within_empty, opt_field, opt_field_named, plain_field_live, range_field, range_field_live, range_field_named, range_field_stepped, @@ -657,6 +657,47 @@ mod field_number_tests { assert_eq!(field_number("50% / 2", "%", false), Some(25.0)); } + /// A field that is not a numeric field widget (a drag value's text, a dialog's text field) reads + /// what a plain field reads: arithmetic, `x` as a multiplication sign and a decimal comma, with + /// `%` and `°` only when the field shows them. + #[test] + fn typed_numbers_take_field_arithmetic() { + for (text, want) in [("45*2", 90.0), ("4x3", 12.0), (" 10 + 5 ", 15.0), ("100/4", 25.0), ("12,5", 12.5), ("7", 7.0)] { + assert_eq!(super::typed_number(text), Some(want), "{text}"); + } + for text in ["", "abc", "1,000", "(12)", "3%", "2°", "1e3", "1 000"] { + assert_eq!(super::typed_number(text), None, "{text}"); + } + assert_eq!(super::typed_number_with("12,5%", "%"), Some(12.5)); + assert_eq!(super::typed_number_with("45°", "°"), Some(45.0)); + assert_eq!(super::typed_number_with("45%", "°"), None, "a mark the field does not show"); + assert_eq!(super::typed_points("4x3"), Some(12.0)); + assert_eq!(super::typed_points("1 in"), Some(72.0)); + assert_eq!(super::typed_points("\u{2212}2"), Some(-2.0)); + assert_eq!(super::typed_number("\u{2212}5"), Some(-5.0), "a minus sign"); + assert_eq!(super::typed_number_with("0.25 s x 2", "s"), Some(0.5), "the field's suffix"); + assert_eq!(super::typed_number("0.25 s"), None, "a suffix the field does not show"); + // The suffix, `%` and `°` only follow an operand; between two digits they are refused. + for (text, suffix) in [("1%2", "%"), ("4°5", "°"), ("0.2s5", "s"), ("%5", "%"), ("2 % 3", "%")] { + assert_eq!(super::typed_number_with(text, suffix), None, "{text}"); + } + assert_eq!(field_number("1%2", "%", false), None, "a numeric field's own suffix"); + assert_eq!(field_number("1%2", "", false), None, "`%` in any field"); + assert_eq!(field_number("50%-2", "%", false), Some(48.0), "subtraction after the suffix"); + assert_eq!(super::typed_number_with("45°\u{2212}15", "°"), Some(30.0), "a minus sign after the suffix"); + assert_eq!(super::typed_number_with("25% + 5%", "%"), Some(30.0)); + } + + /// A field whose suffix is a multiplication sign (the Stroke panel's Limit, `4 x`) reads `x` + /// inside the text as multiplication and only a final one as its suffix. + #[test] + fn a_multiplication_sign_suffix_still_multiplies() { + for (text, want) in [("2x3", 6.0), ("4 x", 4.0), ("2 x 3 x", 6.0), ("5", 5.0), ("10x", 10.0)] { + assert_eq!(field_number(text, " x", false), Some(want), "{text}"); + } + assert_eq!(field_number("x4", " x", false), None); + } + /// A resolution field reads the unit it shows: "200 ppp" in a French interface. #[test] fn a_resolution_field_reads_its_translated_unit() { diff --git a/crates/ui-egui/src/widgets/numeric.rs b/crates/ui-egui/src/widgets/numeric.rs index a9d4020ab3..a3c0ca6a35 100644 --- a/crates/ui-egui/src/widgets/numeric.rs +++ b/crates/ui-egui/src/widgets/numeric.rs @@ -947,9 +947,16 @@ fn bounded_field_reading( /// automatic value as `(12)`), one pair of parentheses around the whole text is dropped first, so /// `(12)` reads as 12. Any other parentheses are refused: `(10+5)*2` reads as nothing, not as /// `10+5*2`. A decimal comma is read ([`decimal_point`]) after the suffix, `%`, `°` and that pair -/// are dropped, so `(1,000)` and `1,000%` are refused as thousands rather than read as 1. +/// are dropped, so `(1,000)` and `1,000%` are refused as thousands rather than read as 1. The +/// suffix, `%` or `°` between two digits is refused: `1%2` reads as nothing, not as 12. A suffix +/// that is a multiplication sign (the Stroke panel's Limit, `4 x`) is the suffix only at the end of +/// the text, so `2x3` reads as 6. pub(super) fn field_number(buf: &str, suffix: &str, parentheses: bool) -> Option { let suffix = suffix.trim(); + let (buf, suffix) = if matches!(suffix, "x" | "X" | "×") { (buf.trim_end().strip_suffix(suffix).unwrap_or(buf), "") } else { (buf, suffix) }; + if !marks_follow_operands(buf, suffix) { + return None; + } let bare = if suffix.is_empty() { buf.to_string() } else { buf.replace(suffix, "") }; let bare = bare.replace(['%', '°'], ""); let bare = bare.trim(); @@ -957,6 +964,43 @@ pub(super) fn field_number(buf: &str, suffix: &str, parentheses: bool) -> Option vectorcraft_doc::parse_number(&decimal_point(bare)) } +/// Whether each `suffix`, `%` and `°` in `buf` comes right after an operand (a digit, a decimal +/// point or comma, or `)`) and is followed only by an operator, `)` or the end of the text. +fn marks_follow_operands(buf: &str, suffix: &str) -> bool { + [suffix, "%", "°"].into_iter().filter(|m| !m.is_empty()).all(|mark| { + buf.match_indices(mark).all(|(at, m)| { + let before = buf.get(..at).and_then(|s| s.trim_end().chars().next_back()); + let after = buf.get(at + m.len()..).and_then(|s| s.trim_start().chars().next()); + before.is_some_and(|c| c.is_ascii_digit() || matches!(c, '.' | ',' | ')')) + && after.is_none_or(|c| matches!(c, '+' | '-' | '*' | '/' | 'x' | 'X' | '×' | ')' | '%' | '°')) + }) + }) +} + +/// A unitless number typed into a field that is not a [`bounded_field`] (an `egui::DragValue`'s +/// parser, a dialog's text field): the same `+ - * /` and `x` arithmetic and decimal comma as +/// [`field_number`], so `45*2`, `4x3` and `12,5` read as 90, 12 and 12.5. `%` and `°` are refused. +pub(crate) fn typed_number(text: &str) -> Option { + typed_number_with(text, "") +} + +/// [`typed_number`] for a field showing `suffix` after its value (`s`, `%` or `°`), which may +/// follow any operand as in [`field_number`]. `%` and `°` are refused unless they are the suffix. +/// A minus sign (U+2212) reads as `-`, as `egui::DragValue`'s own parser reads it. +pub(crate) fn typed_number_with(text: &str, suffix: &str) -> Option { + let suffix = suffix.trim(); + if ['%', '°'].into_iter().any(|mark| text.contains(mark) && !suffix.contains(mark)) { + return None; + } + field_number(&text.replace('\u{2212}', "-"), suffix, false) +} + +/// A length typed into a field that is not a length field widget, in points: a bare number is in +/// points, and a unit, arithmetic and a decimal comma read as in a length field (`4x3`, `2 mm`). +pub(crate) fn typed_points(text: &str) -> Option { + vectorcraft_doc::Unit::Points.parse(&decimal_point(&text.replace('\u{2212}', "-"))) +} + /// The text [`plain_field`] shows for `value`: at most `decimals` places, without trailing zeros, /// then `suffix`. pub(super) fn field_text(value: f64, suffix: &str, decimals: usize) -> String { diff --git a/docs/mcp.md b/docs/mcp.md index 5a2c7eeb7d..6bcdc37895 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -11924,7 +11924,8 @@ outside its range is refused with `` `warichuLines` must be a whole number from `` `warichuScale` must be from 10 to 100 ``, naming the key, and an unknown alignment with the list of the values. One undo step; a `text.setFormat` call that changes nothing records none. `ui.warichuSettings` opens the Warichu Settings dialog on the values the selected characters share, a blank field where they differ; OK sends the values that changed and leaves a -blank field's value alone. OK with a field that is not a number returns `Lines must be a number`, +blank field's value alone. Lines and Scale given as text take the arithmetic of the app's number fields (`"1+2"`, +`"30x2%"`); `%` is read only in Scale. OK with a field that is not a number returns `Lines must be a number`, `Line Gap must be a number` or `Scale must be a number` and keeps the dialog open. ```json @@ -12928,7 +12929,10 @@ dialog exposes `name`, `font_family`, `font_style`, `size`, `leading`, `kerning` `tcyLeftRight`, `rotation`, `akiLeft`, `akiRight`, `tsume`, `diacriticHorizontal`, `diacriticVertical`, `language`, `fill`, `fill_tint`, `stroke`, `stroke_tint`, `stroke_width`, `overprint_fill`, `overprint_stroke`, `ot_figure`, `ot_position`, `ot_liga`, `ot_calt`, `ot_dlig`, `ot_swsh`, `ot_salt`, `ot_titl`, `ot_ordn`, `ot_frac`, `ot_sets`, `section` (`general`, `basic`, `advanced`, `color` or `opentype`), and `preview`. An empty field leaves its -attribute unset. `leading` and `kerning` also accept `Auto` to store an explicit automatic value. +attribute unset. `leading` and `kerning` also accept `Auto` to store an explicit automatic value. A number field +given as text takes the arithmetic of the app's number fields (`"6x2"`, `"10+4"`); `size`, `leading`, `baseline_shift`, +`tcyUpDown`, `tcyLeftRight` and `stroke_width` also read a unit (`"1 in"`), `%` is read only in `h_scale`, `v_scale`, +`fill_tint` and `stroke_tint`, and `°` only in `rotation`. Advanced Character Formats holds `h_scale` and `v_scale` (percent, 1 to 10000), `baseline_shift` (points, -1296 to 1296), the Tate-chu-yoko Settings `tcyUpDown` and `tcyLeftRight` (points, -1296 to 1296, as `text.setRangeStyle` takes them; an explicit 0 stays distinct from unset), `rotation` (degrees, stored from -180 to 180), Insert Aki Left and Right `akiLeft` and `akiRight` (thousandths of diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 125b9f2019..4edb10df12 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1075,6 +1075,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Numeric fields keep the pointer's pressed character as the text-drag start when movement exceeds the click threshold (#1326); a completed focus click selects the unit too. Pixel/point, plain and optional fields are regression-tested in both directions, before/after focus, with replacement text; keyboard focus, double-click, arrows and wheel keep their prior behavior. Native egui input confirms partial replacement gives 17 px instead of 700 px, one Undo/Redo, window captures and an exact saved-document read in a separate CLI process. A focus click released more than 1 pt from its press keeps the caret, and a tap within 1 pt still selects all (#6659; short-drag and jitter-tap regressions in `tests/numfields.rs`). - Unit fields and length strings take `%` in arithmetic: `3cm*50%` reads as 1.5 cm, and `50pt+25%` reads as 62.5 pt. - Value fields and length strings read `x` as a multiplication sign, as they read `*` (#8435; the help's "Calculate values in a panel or dialog box" lists `x` for multiplication: [help PDF, archived](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf)). `X` and `×` also multiply; that is VectorCraft's own choice. `10x2` reads as 20 and `2x3 mm` as 6 mm. A lowercase `x` right after a `p` stays the `px` unit (`2px x 3` is 6 px, and `2px3` is not read). Tests: `x_is_a_multiplication_sign` in `crates/doc/src/tests/units.rs`. + - The number fields drawn without the shared field widgets read typed text with the same arithmetic: the Contour bar's distance (`4x3` is 12 pt, `2 mm` is 2 mm), Graph Data's Number of Decimals and Column Width, Map Art's surface number, the Keyboard Shortcuts dialog's Hold Shortcut Delay, the unitless values of the 3D effect dialogs and the number fields of Character Style Options, whose length fields also read a unit (`1 in` is 72 pt). Warichu Settings' Lines and Scale read text given through `ui.dialog.set` (MCP `answer_dialog`) the same way. These fields take `%` and `°` only where they show them. An exponent (`1e3`) and a space inside a number (`1 000`) are not read in these fields, though several of them read both before. In the shared unitless fields a unit suffix, `%` or `°` between two digits is refused (`1%2` was read as 12), and the Stroke panel's Limit reads `2x3` as 6 (it read 23). Tests: the `vectorcraft-ui-egui` tests whose names end in `take_field_arithmetic`, `warichu_settings_dialog_reads_field_arithmetic` and `a_multiplication_sign_suffix_still_multiplies`. - The contextual task bar's handle drags it anywhere on the canvas (kept whole on it as the window resizes); unpinned it keeps that offset as it follows the selection, and its More Options menu hides it, pins its position across selection changes (`window.taskBar.pin`), resets it under the selection (`window.taskBar.reset`) and shows the Properties panel. As in Illustrator the position isn't kept across launches. Not done: the bar's variants for other tools (only the selection tools, the Type tools, the basic shape tools, the Smooth tool and the Artboard tool show it). - A click on another object moves the contextual task bar under it without hiding it for the press; it gives way only to a drag (#4681). - With one image selected, the contextual task bar offers Image Trace, which traces the image at once with the Default preset (the Image Trace panel is left as it was), and Crop Image; with an Image Trace object it offers Expand, which keeps only the traced paths. This follows Illustrator's bar: for a selected image it includes Image Trace, Retype and Crop Image, and traced artwork can be expanded from it ([Contextual Task Bar announcement](https://community.adobe.com/announcements-651/contextual-task-bar-in-illustrator-2025-quick-actions-when-you-need-them-1546580)). Offset Path and Simplify, which don't apply to an image, aren't offered for one. Not done: Retype, which the app doesn't have. From c3c2b0294ed28ca7d0ae3773dd2938ef70c03f9e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 19 Nov 2026 16:41:48 -0800 Subject: [PATCH 04/26] Fields: Tsume reads a percent sign like the other percent fields The Tsume field in Advanced Character Formats shows a % beside it but read its text as a unitless number, so 25% and 50%/2 were rejected with "Tsume must be a number". It now takes the percent field dispatch; the 0 to 100 clamp still applies. --- crates/ui-egui/src/dialogs/char_style_options.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/dialogs/char_style_options.rs b/crates/ui-egui/src/dialogs/char_style_options.rs index cf47c85156..f5174d1231 100644 --- a/crates/ui-egui/src/dialogs/char_style_options.rs +++ b/crates/ui-egui/src/dialogs/char_style_options.rs @@ -315,7 +315,7 @@ fn case_from_attrs(attrs: &Map) -> Option<&'static str> { fn typed_number(key: &str, text: &str) -> Option { match key { "size" | "leading" | "baseline_shift" | "tcyUpDown" | "tcyLeftRight" | "stroke_width" => crate::widgets::typed_points(text), - "h_scale" | "v_scale" | "fill_tint" | "stroke_tint" => crate::widgets::typed_number_with(text, "%"), + "h_scale" | "v_scale" | "tsume" | "fill_tint" | "stroke_tint" => crate::widgets::typed_number_with(text, "%"), "rotation" => crate::widgets::typed_number_with(text, "°"), _ => crate::widgets::typed_number(text), } @@ -2017,7 +2017,7 @@ mod tests { assert_eq!(d.fields["tsume"], json!("")); let mut d = dialog_for(json!({"tsume": 50.0})); assert_eq!(d.fields["tsume"], json!(50.0)); - for (typed, kept) in [("0", 0.0), ("25.5", 25.5), ("150", 100.0), ("-5", 0.0)] { + for (typed, kept) in [("0", 0.0), ("25.5", 25.5), ("25%", 25.0), ("50%/2", 25.0), ("150", 100.0), ("-5", 0.0)] { d.fields.insert("tsume".into(), json!(typed)); assert_eq!(edited_attrs(&d).unwrap(), attrs(json!({"tsume": kept})), "{typed}"); } From 691201b7487364f9bdd27bdd8a1c5d21883c264e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 14:30:03 -0800 Subject: [PATCH 05/26] Layers: a layer or sublayer with all its art selected shows the full-sized square The selection square of a layer or sublayer is full-sized while all of its visible, unlocked art is selected, and small while only some of it is. Hidden, locked and template art does not keep the square small, a group counts as one item (a selected member is not the group), and a layer with no such art shows no square. Group rows are unchanged. The panel finds these layers once per frame, in one pass over the layers and their direct children, and the untargeted target circle of a layer reads the same set. Help page: https://helpx.adobe.com/illustrator/desktop/manage-layers/create-and-organize-layers/layers-overview.html --- crates/ui-egui/src/panels/layers.rs | 7 ++- crates/ui-egui/src/panels/layers/rows.rs | 49 ++++++++++++---- crates/ui-egui/src/panels/layers/tests.rs | 70 +++++++++++++++++++++++ docs/target-app-parity.md | 1 + 4 files changed, 116 insertions(+), 11 deletions(-) diff --git a/crates/ui-egui/src/panels/layers.rs b/crates/ui-egui/src/panels/layers.rs index 93aa99e6da..e2ebe3c4fa 100644 --- a/crates/ui-egui/src/panels/layers.rs +++ b/crates/ui-egui/src/panels/layers.rs @@ -162,6 +162,9 @@ struct View<'a> { /// Where the row thumbnails come from. thumbs: ThumbSource<'a>, sel: HashSet, + /// The layers and sublayers whose visible, unlocked art ([`Node::layer_art`]) is all selected + /// and not empty. + full_layers: HashSet, /// The selected ruler guides, as indexes into [`Self::ruler_guides`]. guides: Vec, /// The document's ruler guides ([`Document::ruler_guides`]). @@ -320,10 +323,12 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { let reveal = renamed.or(located).or(reveal); let Some(st) = app.session.active() else { return }; let list = rows_of_doc(ui, st, &app.ui.layers_panel, &query, &app.ui.layers_filter); + let sel: HashSet = st.selection.objects.iter().copied().collect(); let view = View { doc: &doc, thumbs: ThumbSource::of(app, st, &doc), - sel: st.selection.objects.iter().copied().collect(), + full_layers: rows::full_layers(&doc, &sel), + sel, guides: vectorcraft_engine::cmd::guide_indexes(&doc, &st.selection.guides), ruler_guides: doc.ruler_guides(), target: st.selection.target, diff --git a/crates/ui-egui/src/panels/layers/rows.rs b/crates/ui-egui/src/panels/layers/rows.rs index c945537326..34fb517a26 100644 --- a/crates/ui-egui/src/panels/layers/rows.rs +++ b/crates/ui-egui/src/panels/layers/rows.rs @@ -2,8 +2,8 @@ use super::controls::collect_for_export_menu; use super::model::{Place, Row, opens, painted_name}; use super::thumbs::{node_arc, real_thumb, thumb}; use super::{ - Arc, COLUMN, Color32, ColumnDrag, Document, INDENT, LayersDrag, Node, NodeId, NodeKind, Out, PanelDrag, ROW_KEYS, SQUARE_X, Sense, Stroke, - StrokeKind, TARGET_X, Tokens, Ui, Value, View, icons, json, vec2, widgets, + Arc, COLUMN, Color32, ColumnDrag, Document, HashSet, INDENT, LayersDrag, Node, NodeId, NodeKind, Out, PanelDrag, ROW_KEYS, SQUARE_X, Sense, + Stroke, StrokeKind, TARGET_X, Tokens, Ui, Value, View, icons, json, vec2, widgets, }; use vectorcraft_tools::intertwine::{in_intertwine, refused_member}; @@ -499,6 +499,8 @@ pub(super) fn row(ui: &mut Ui, view: &View, item: &Row, out: &mut Out) { n.walk(&mut |c| any |= c.id != n.id && view.sel.contains(&c.id)); any }); + // A layer or sublayer whose selectable art is all selected shows the full-sized square. + let full = view.full_layers.contains(&n.id); row_background(ui, view, n, r, &resp); eye_and_lock(ui, view, n, r, out); // Layer colour bar (every row shows the colour of its layer). @@ -523,7 +525,7 @@ pub(super) fn row(ui: &mut Ui, view: &View, item: &Row, out: &mut Out) { let tc = egui::pos2(r.right() - TARGET_X, r.center().y); let tresp = target_circle(ui, n, tc, h, shows_targeted(view, n, is_sel), &mut out.actions, t); let sq = egui::pos2(r.right() - SQUARE_X, r.center().y); - if is_sel { + if is_sel || full { let q = egui::Rect::from_center_size(sq, vec2(7.0, 7.0)); ui.painter().rect_filled(q, 0.0, color); ui.painter().rect_stroke(q, 0.0, Stroke::new(1.0, t.text), StrokeKind::Inside); @@ -938,17 +940,44 @@ fn drop_target(ui: &Ui, view: &View, n: &Node, r: egui::Rect, indent: f32, open: fn shows_targeted(view: &View, n: &Node, is_sel: bool) -> bool { match view.target { Some(id) => id == n.id, - None if n.is_layer() => { - if view.sel.is_empty() { - return false; - } - let art = n.layer_art(true); - !art.is_empty() && art.iter().all(|id| view.sel.contains(id)) - } + None if n.is_layer() => view.full_layers.contains(&n.id), None => is_sel, } } +/// The layers and sublayers of `doc` whose [`Node::layer_art`] with `editable` is not empty and +/// all in `sel`, found in one pass over the layers and their direct children. +pub(super) fn full_layers(doc: &Document, sel: &HashSet) -> HashSet { + /// Adds `layer` to `out` when it is full, and returns its art's count and selected count. + fn visit(layer: &Node, sel: &HashSet, out: &mut HashSet) -> (usize, usize) { + let (mut art, mut selected) = (0, 0); + for c in layer.children().into_iter().flatten() { + let counts = !(c.is_ruler_guide() || !c.visible || c.locked || c.is_template()); + if c.is_layer() { + let (a, s) = visit(c, sel, out); + if counts { + art += a; + selected += s; + } + } else if counts { + art += 1; + selected += usize::from(sel.contains(&c.id)); + } + } + if art > 0 && selected == art { + out.insert(layer.id); + } + (art, selected) + } + let mut out = HashSet::new(); + if !sel.is_empty() { + for layer in doc.layers.iter().filter(|l| l.is_layer()) { + visit(layer, sel, &mut out); + } + } + out +} + /// The radius of the inner ring of a targeted item's target circle (the double ring); the outer /// ring's radius is 5. pub(super) const TARGET_RING: f32 = 2.8; diff --git a/crates/ui-egui/src/panels/layers/tests.rs b/crates/ui-egui/src/panels/layers/tests.rs index 0fddbc41a8..aa029563e9 100644 --- a/crates/ui-egui/src/panels/layers/tests.rs +++ b/crates/ui-egui/src/panels/layers/tests.rs @@ -1610,6 +1610,76 @@ fn selection_squares_show_and_select_a_rows_art() { let _ = (layer, sub, b); } +/// A layer or sublayer whose selectable art is all selected shows the full-sized square; one +/// holding some of its art, or a group's member instead of the group, shows the small one. +#[test] +fn a_layer_with_all_its_art_selected_shows_the_full_square() { + let (mut app, [_, _, g, b, a, c]) = nested(); + let ctx = egui::Context::default(); + let (circles, _) = frame(&mut app, &ctx, vec![], false); + let square = |i: usize| circles[i] + vec2(TARGET_X - SQUARE_X, 0.0); + app.session.execute("select.set", &json!({"ids": [a.0]})).unwrap(); + assert_eq!(squares(&mut app, &ctx), (1, 2), "the rectangle's square, small ones on the sublayer and the layer"); + app.session.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap(); + assert_eq!(squares(&mut app, &ctx), (2, 3), "a group's member is not the group: the sublayer's square stays small"); + click_with(&mut app, &ctx, square(1), egui::Modifiers::NONE); + assert_eq!(squares(&mut app, &ctx), (3, 1), "the sublayer, its group and rectangle full, the layer small"); + click_with(&mut app, &ctx, square(0), egui::Modifiers::NONE); + assert_eq!(squares(&mut app, &ctx), (5, 0), "the layer and the sublayer full, with each row's art"); + click_with(&mut app, &ctx, square(4), egui::Modifiers::SHIFT); + assert_eq!(squares(&mut app, &ctx), (2, 2), "one rectangle let go: the layer and the sublayer small again"); + // Locked art cannot be selected, so it does not keep the layer's square small. + app.session.execute("layer.setProps", &json!({"ids": [c.0], "locked": true})).unwrap(); + click_with(&mut app, &ctx, square(1), egui::Modifiers::NONE); + assert_eq!(squares(&mut app, &ctx), (4, 0), "the layer, the sublayer, the group and the rectangle"); + // Hidden art neither. + app.session.execute("layer.setProps", &json!({"ids": [c.0], "locked": false, "visible": false})).unwrap(); + app.session.execute("select.set", &json!({"ids": [a.0, g.0]})).unwrap(); + assert_eq!(squares(&mut app, &ctx), (4, 0), "hidden art is left out"); +} + +/// A layer with no selectable art shows no square, whatever else is selected. +#[test] +fn a_layer_without_art_shows_no_square() { + let (mut app, [_, _, g, _, a, c]) = nested(); + app.session.execute("layer.new", &json!({})).unwrap(); + let ctx = egui::Context::default(); + app.session.execute("select.set", &json!({"ids": [c.0, a.0, g.0]})).unwrap(); + assert_eq!(squares(&mut app, &ctx), (5, 0), "the first layer's rows; the new, empty layer's none"); +} + +/// The panel's set of full layers is the layers and sublayers whose `layer_art(true)` is not empty +/// and all selected, for every selection of the document's objects, hidden and locked ones included. +#[test] +fn full_layers_are_the_layers_with_all_their_art_selected() { + let (mut app, [_, _, _, _, _, c]) = nested(); + let run = |app: &mut VectorcraftApp, id: &str, p: serde_json::Value| app.session.execute(id, &p).unwrap(); + let id = |v: serde_json::Value| NodeId(v["id"].as_u64().unwrap()); + let hidden = id(run(&mut app, "layer.newSublayer", json!({"name": "Hidden"}))); + run(&mut app, "shape.rectangle", json!({"x": 200, "y": 0, "width": 20, "height": 20})); + run(&mut app, "layer.setProps", json!({"ids": [hidden.0], "visible": false})); + run(&mut app, "layer.setProps", json!({"ids": [c.0], "locked": true})); + run(&mut app, "layer.new", json!({})); + let doc = app.session.active().unwrap().doc.clone(); + let (mut layers, mut objects) = (vec![], vec![]); + for l in &doc.layers { + l.walk(&mut |n| if n.is_layer() { layers.push(n) } else { objects.push(n.id) }); + } + assert_eq!((layers.len(), objects.len()), (4, 5), "the layers, the sublayers and the objects"); + for bits in 0u32..(1 << objects.len()) { + let sel: HashSet = objects.iter().enumerate().filter(|(i, _)| (bits >> i) & 1 == 1).map(|(_, id)| *id).collect(); + let want: HashSet = layers + .iter() + .filter(|l| { + let art = l.layer_art(true); + !art.is_empty() && art.iter().all(|i| sel.contains(i)) + }) + .map(|l| l.id) + .collect(); + assert_eq!(rows::full_layers(&doc, &sel), want, "selection {bits:b}"); + } +} + /// Alt-click on a layer's or sublayer's name makes it current, as a plain click does, and selects /// its art, as its selection square does. On another row, beside the name or with Shift or Ctrl/Cmd /// held too, it is the click without Alt. diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 57ac87a396..9d60731b43 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1600,6 +1600,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur Ctrl/Cmd+Alt-clicking an eye switches the other layers to Outline and the row's layer to Preview, or switches all layers back to Preview when the others are in Outline (`layer.outlineOthers`, `layer.previewAll`). Ctrl/Cmd+Alt-clicking New Layer adds a layer directly below the current layer, at its level (`layer.new {below: true}`), and Ctrl/Cmd+Alt-clicking New Sublayer adds a sublayer under the contents of the layer it goes into (`layer.newSublayer {bottom: true}`), each in one undo step. The reference app's [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) page lists these clicks for placing a layer below the selected layer and a new sublayer at the bottom of the layer list. Alt-clicking a layer's or sublayer's name makes it the current layer, as a click does, and selects its visible, unlocked art, as its selection square does (`layer.selectAll`, then `layer.setCurrent`); on a hidden or locked layer it clears the selection. The reference app's [Default keyboard shortcuts](https://web.archive.org/web/20260726060015/https://helpx.adobe.com/illustrator/using/default-keyboard-shortcuts.html) page lists Alt-click on the layer name for selecting all objects on the layer. + A layer or sublayer whose selectable art is all selected shows the full-sized selection square instead of the small one, as the [help page](https://helpx.adobe.com/illustrator/desktop/manage-layers/create-and-organize-layers/layers-overview.html) describes for a layer with every item selected. As VectorCraft's own rules, sublayers follow the same rule, "all" means the visible, unlocked art its selection square selects (hidden or locked art does not keep the square small, and a selected member of a group is not the group), and a layer with no such art shows no square. A group row keeps the small square while only its members are selected (`panels::layers` tests `a_layer_with_all_its_art_selected_shows_the_full_square`, `a_layer_without_art_shows_no_square` and `full_layers_are_the_layers_with_all_their_art_selected`). Object › Arrange › Send to Current Layer returns the error "the target layer is locked or hidden" and leaves the selected objects where they are when the current layer is hidden or locked, or is inside a hidden or locked layer. Selected objects are deselected, the key object included, when a row drag moves them into a hidden layer or group, when `node.move` moves them into a hidden or locked layer or group, when Merge Selected moves them into a hidden or locked layer, when Collect in New Layer moves them into a new layer inside a hidden or locked layer, when Flatten Artwork moves them into a locked layer, and when applying a data set hides them. Layer Options for several highlighted rows shows the first row's settings, and OK changes only the settings set in the dialog: each row keeps its own color, Template, Lock, Show, Print, Preview and Dim Images otherwise (`crates/ui-egui/src/dialogs/layer_options.rs` tests). From e5380cd7960c285d049f7b4ea444d71e9447a9d3 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 14:34:28 -0800 Subject: [PATCH 06/26] Tabs: a position typed in X or Y adds a stop when the paragraph has none When the shown paragraph has no tab stops and no indent marker is selected, a position typed in the Tabs panel's X field (Y in vertical type) and committed with Enter now adds a stop there with the chosen alignment and selects it, in one text.tabs.set and one undo step, as a click on the ruler does. Before, the typed value was dropped. The archived user guide gives typing a position as another way to set a new stop: https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=521 The typed value keeps its hundredths of a point and is read in the General unit unless it names another unit. A negative position becomes 0 pt and a position past 100,000 pt adds nothing; these are VectorCraft's own limits. With the Selection tool on several texts, the new stop is set on every selected text, as a ruler click already does. The ruler click and the typed position share one helper, so a click whose text.tabs.set fails no longer moves the selection. --- crates/ui-egui/src/panels/tabs.rs | 57 +++++++----- crates/ui-egui/src/panels/tabs/tests.rs | 110 ++++++++++++++++++++++++ docs/target-app-parity.md | 2 +- 3 files changed, 147 insertions(+), 22 deletions(-) diff --git a/crates/ui-egui/src/panels/tabs.rs b/crates/ui-egui/src/panels/tabs.rs index a09c634967..a927c5a6bf 100644 --- a/crates/ui-egui/src/panels/tabs.rs +++ b/crates/ui-egui/src/panels/tabs.rs @@ -1,4 +1,5 @@ -//! Tabs panel: tab-stop alignment, X position (Y in vertical type), leader and "align on", and a +//! Tabs panel: tab-stop alignment, X position (Y in vertical type; a position typed there for a +//! paragraph with no stops adds a stop at it), leader and "align on", and a //! ruler numbered in the General unit on which a click adds a stop, dragging moves one and dragging //! it off the ruler deletes it. Ctrl-dragging a stop (Command on macOS) moves all the stops by the //! same distance. A stop placed or dragged on the ruler lands on the nearest whole point. With Snap @@ -462,6 +463,32 @@ fn apply_moved(app: &mut VectorcraftApp, ctx: &egui::Context, stops: &mut Vec, position: f64, align: TabAlign) -> Option { + let mut added = stops.clone(); + if !added.iter().any(|s| s.position == position) { + let max = TabStop::MAX_STOPS; + if added.len() >= max { + app.status(format!("at most {max} tab stops")); + return None; + } + added.push(TabStop { position, align, leader: String::new(), align_on: '.' }); + added.sort_by(|a, b| a.position.total_cmp(&b.position)); + if !apply(app, &added) { + return None; + } + } + let i = added.iter().position(|s| s.position == position).unwrap_or(0); + *stops = added; + set_pstate::>(ctx, "tabs-marker-sel", None); + set_pstate(ctx, "tabs-sel", i); + Some(i) +} + /// `stops` with every stop moved by the distance that takes stop `i` to `position`, or by less /// when that would put a stop below 0 or past [`MAX_STOP`], so the leftmost stop ends at 0 or the /// rightmost at [`MAX_STOP`] and the stops keep their spacing. The stops keep their order, @@ -622,6 +649,11 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { if let Some(v) = widgets::spin_field(ui, "tabs-x", x, app.session.general_unit(), 90.0, 1.0, 0.0, &[]) { if let Some(marker) = selected_marker { set_marker(app, marker, v, ¶, span, &targets, false); + } else if stops.is_empty() { + // With no stops, the typed position adds the first one, as a click on the ruler does. + if let Some(i) = add_stop(app, ui.ctx(), &mut stops, v.max(0.0), ALIGNS[align_idx.min(3)].0) { + sel = i; + } } else if let Some(i) = apply_moved(app, ui.ctx(), &mut stops, sel, v.max(0.0)) { sel = i; } @@ -800,27 +832,10 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { set_pstate(ui.ctx(), "tabs-sel", i); } None => { - let position = place(pos.x); // A click that lands on a stop's whole point or tick selects that stop and records no - // undo step. - let added = !stops.iter().any(|s| s.position == position); - let max = TabStop::MAX_STOPS; - if added && stops.len() >= max { - // A full list takes no more stops: the click leaves the stops and the - // selection as they are and shows the limit. - app.status(format!("at most {max} tab stops")); - } else { - if added { - stops.push(TabStop { position, align: ALIGNS[align_idx.min(3)].0, leader: String::new(), align_on: '.' }); - stops.sort_by(|a, b| a.position.total_cmp(&b.position)); - } - let i = stops.iter().position(|s| s.position == position).unwrap_or(0); - set_pstate::>(ui.ctx(), "tabs-marker-sel", None); - set_pstate(ui.ctx(), "tabs-sel", i); - if added { - apply(app, &stops); - } - } + // undo step. A full list takes no more stops: the click leaves the stops and the + // selection as they are and shows the limit. + add_stop(app, ui.ctx(), &mut stops, place(pos.x), ALIGNS[align_idx.min(3)].0); } } } diff --git a/crates/ui-egui/src/panels/tabs/tests.rs b/crates/ui-egui/src/panels/tabs/tests.rs index 37d2a4d93d..6edba53c3a 100644 --- a/crates/ui-egui/src/panels/tabs/tests.rs +++ b/crates/ui-egui/src/panels/tabs/tests.rs @@ -1577,6 +1577,116 @@ fn a_refused_x_leaves_the_ruler_as_it_was() { assert_eq!(committed, before); } +/// Click the position field to the right of the label `label` ("X:" or "Y:"), which is blank +/// while the paragraph has no stops, type `typed` and press Enter → the texts painted next. +fn type_into_blank_position(ctx: &egui::Context, app: &mut VectorcraftApp, label: &str, typed: &str) -> Vec<(String, egui::Rect)> { + let texts = panel_frame(ctx, app, vec![]); + let rect_of = |name: &str| texts.iter().find(|(t, _)| t == name).unwrap_or_else(|| panic!("{name} in {texts:?}")).1; + // The fields' column starts after the widest label, "Align On:". + let at = egui::pos2(rect_of("Align On:").right() + 6.0 + 45.0, rect_of(label).center().y); + let button = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; + let key = |key, modifiers| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }; + panel_frame(ctx, app, vec![egui::Event::PointerMoved(at), button(true)]); + panel_frame(ctx, app, vec![button(false)]); + panel_frame(ctx, app, vec![key(egui::Key::A, egui::Modifiers::COMMAND)]); + panel_frame(ctx, app, vec![egui::Event::Text(typed.into())]); + panel_frame(ctx, app, vec![key(egui::Key::Enter, egui::Modifiers::NONE)]); + panel_frame(ctx, app, vec![]) +} + +/// A position typed in the X field of a paragraph with no stops adds a stop there with the chosen +/// alignment, keeps its hundredths of a point, selects it, and is one undo step. +#[test] +fn typing_x_into_a_paragraph_without_stops_adds_and_selects_a_stop() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({})).unwrap(); + app.run("text.create", json!({"x": 10, "y": 20, "text": "a\tb", "area": {"width": 300, "height": 100}})).unwrap(); + assert!(current(&app).unwrap().1.is_empty()); + let ctx = egui::Context::default(); + set_pstate(&ctx, "tabs-align", 2usize); + let before = app.session.active().unwrap().history.undo.len(); + let texts = type_into_blank_position(&ctx, &mut app, "X:", "36.47"); + let stops = current(&app).unwrap().1; + assert_eq!(stops.iter().map(|s| (s.position, s.align)).collect::>(), [(36.47, TabAlign::Right)]); + assert_eq!(pstate::(&ctx, "tabs-sel"), 0); + assert!(texts.iter().any(|(t, _)| t == "36.47 pt"), "36.47 pt in {texts:?}"); + assert_eq!(app.session.active().unwrap().history.undo.len(), before + 1); + app.run("edit.undo", json!({})).unwrap(); + assert!(current(&app).unwrap().1.is_empty()); +} + +/// In vertical type the position field is Y, and a position typed there for a paragraph with no +/// stops adds a stop. +#[test] +fn typing_y_into_vertical_type_without_stops_adds_a_stop() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({})).unwrap(); + app.run("text.create", json!({"x": 10, "y": 20, "text": "a\tb", "vertical": true})).unwrap(); + let ctx = egui::Context::default(); + type_into_blank_position(&ctx, &mut app, "Y:", "48"); + let stops = current(&app).unwrap().1; + assert_eq!(stops.iter().map(|s| (s.position, s.align)).collect::>(), [(48.0, TabAlign::Left)]); +} + +/// A first stop typed with a unit other than the document's lands at that distance in points, and +/// one typed without a unit is in the document's unit. +#[test] +fn a_first_stop_typed_in_another_unit_keeps_its_point_position() { + for typed in ["1 in", "25.4"] { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({})).unwrap(); + app.run("document.setUnits", json!({"units": "mm"})).unwrap(); + app.run("text.create", json!({"x": 10, "y": 20, "text": "a\tb", "area": {"width": 300, "height": 100}})).unwrap(); + let ctx = egui::Context::default(); + type_into_blank_position(&ctx, &mut app, "X:", typed); + let positions = current(&app).unwrap().1.iter().map(|s| s.position).collect::>(); + assert_eq!(positions.len(), 1, "{typed}: {positions:?}"); + assert!((positions[0] - 72.0).abs() < 1e-9, "{typed}: {positions:?}"); + } +} + +/// A first stop past 100,000 pt or text that is not a number adds no stop and records no undo +/// step. A negative position adds the stop at 0 pt. +#[test] +fn a_refused_first_stop_adds_nothing_and_records_no_undo() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({})).unwrap(); + app.run("text.create", json!({"x": 10, "y": 20, "text": "a\tb", "area": {"width": 300, "height": 100}})).unwrap(); + let ctx = egui::Context::default(); + let steps = |app: &VectorcraftApp| app.session.active().unwrap().history.undo.len(); + let before = steps(&app); + for typed in ["200000", "abc"] { + type_into_blank_position(&ctx, &mut app, "X:", typed); + assert!(current(&app).unwrap().1.is_empty(), "{typed}"); + assert_eq!(steps(&app), before, "{typed}"); + } + type_into_blank_position(&ctx, &mut app, "X:", "-5"); + assert_eq!(current(&app).unwrap().1.iter().map(|s| s.position).collect::>(), [0.0]); + assert_eq!(steps(&app), before + 1); +} + +/// With the Selection tool on two texts, a first stop typed for the shown text, which has no +/// stops, becomes every selected text's stops in one undo step, replacing the other text's stop. +#[test] +fn typing_the_first_stop_over_mixed_paragraphs_uses_the_displayed_list() { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({})).unwrap(); + let id = |v: serde_json::Value| v["id"].as_u64().unwrap(); + let a = id(app.run("text.create", json!({"x": 10, "y": 20, "text": "a\tb", "area": {"width": 300, "height": 60}})).unwrap()); + let b = id(app.run("text.create", json!({"x": 10, "y": 100, "text": "c\td", "area": {"width": 250, "height": 60}})).unwrap()); + app.run("select.set", json!({"ids": [b]})).unwrap(); + app.run("text.tabs.set", json!({"stops": [{"position": 90}]})).unwrap(); + app.run("select.set", json!({"ids": [a, b]})).unwrap(); + assert_eq!(current(&app).unwrap().0.id.0, a); + let ctx = egui::Context::default(); + let before = app.session.active().unwrap().history.undo.len(); + type_into_blank_position(&ctx, &mut app, "X:", "25"); + for text in [a, b] { + assert_eq!(text_of(&app, text).para_at(0).tabs.iter().map(|s| s.position).collect::>(), [25.0], "text {text}"); + } + assert_eq!(app.session.active().unwrap().history.undo.len(), before + 1); +} + /// One frame of the panel menu with `events` → the rows' texts and where they are painted. fn menu_frame(ctx: &egui::Context, app: &mut VectorcraftApp, events: Vec) -> Vec<(String, egui::Rect)> { let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, vec2(320.0, 400.0)); diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 57ac87a396..f43060eb9f 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -1829,7 +1829,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur The Character panel menu's Character Direction (with the Indic options; `text.setFormat {charDirection}`, `text.setRangeStyle {charDirection}`) sets the selected characters left to right or right to left inside their paragraph, as a Unicode bidi embedding: a date set Left to Right keeps its order in right-to-left text, and a word set Right to Left keeps the punctuation after it on its left. Default (the default) leaves the characters to the bidi algorithm; character styles and the native file keep the setting. In vertical type, the Tabs panel names its alignment buttons Top-Justified Tab, Center-Justified Tab, Bottom-Justified Tab and Decimal-Justified Tab, in their tool tips and for screen readers, and labels the position field Y. In horizontal type the buttons keep the names Left-Justified Tab and Right-Justified Tab, and the field keeps the label X. The Tabs panel's ruler is numbered in the General unit with the canvas rulers' label steps and a tick every tenth of a step. With the panel menu's Snap to Unit on, or Shift held, a tab stop placed by a click on the ruler or dragged on it lands on the nearest tick (`text.tabs.set`). - With Snap to Unit off and Shift not held, a tab stop placed by a click on the Tabs panel's ruler or dragged on it lands on the nearest whole point. A position typed in the X or Y field keeps its hundredths of a point. + With Snap to Unit off and Shift not held, a tab stop placed by a click on the Tabs panel's ruler or dragged on it lands on the nearest whole point. A position typed in the X or Y field keeps its hundredths of a point. When the shown paragraph has no tab stops and no indent marker is selected, a position typed in the X or Y field and committed with Enter adds a stop there with the chosen alignment and selects it, in one undo step, as a click on the ruler does; the [archived user guide](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=521) gives typing a position as another way to set a new stop. A negative position becomes 0 pt, and a position past 100,000 pt adds nothing (VectorCraft's own limits). Tests `panels::tabs::tests::typing_x_into_a_paragraph_without_stops_adds_and_selects_a_stop`, `typing_y_into_vertical_type_without_stops_adds_a_stop`, `a_first_stop_typed_in_another_unit_keeps_its_point_position`, `a_refused_first_stop_adds_nothing_and_records_no_undo` and `typing_the_first_stop_over_mixed_paragraphs_uses_the_displayed_list`. The Tabs ruler's upper first-line marker and lower left-indent marker show absolute positions and set paragraph indents (`text.setFormat`). Dragging the lower marker keeps the upper position, while Ctrl-dragging it (Command on macOS) moves both; marker drags snap like tab stops, and each release is one undo step. With differing left indents, only the upper marker is shown and its absolute target applies to every touched paragraph. When a drag on the Tabs panel's ruler or a value typed in its X field moves a tab stop past another stop, the moved stop stays selected. With the Selection tool, the Tabs panel shows the ruler and stops of the first paragraph of the first selected text object, also when the text is inside a selected group or a shape is selected before it; a selection without text shows "No text selected". A stop set on that ruler is set on every selected text object and the text in selected groups, and other objects are left as they were. This is VectorCraft's own rule. Tests `panels::tabs::tests::the_ruler_shows_text_selected_after_an_object_that_is_not_text`, `the_ruler_shows_text_inside_a_selected_group`, `a_stop_added_on_a_mixed_selection_sets_every_selected_text` and `a_selection_without_text_shows_no_ruler`. From c51fc47b30b1a3dc429fa6c069f19b77b95dd2fc Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 20 Nov 2026 21:14:38 -0800 Subject: [PATCH 07/26] Save for Web: a color shift survives Done right after the Color Picker, stops at 256 colors and matches keys written another way - Done or Save right after the Color Picker's OK, before the dialog draws again, now applies the picked shift, so the saved and remembered settings keep it. - Shifting a 257th color now changes nothing and the status bar shows the engine's limit; shifting an already shifted color again, or taking a shift away, still works. - Unshift, a new shift and the Lock, Transparent and Web Shift lists compare colors rather than text, so a key such as `#F00` is replaced instead of left beside `#ff0000`. Docs: docs/mcp.md. --- crates/engine/src/cmd/webexport.rs | 9 ++- crates/ui-egui/src/dialogs/save_for_web.rs | 44 +++++++++---- .../ui-egui/src/dialogs/tests_save_for_web.rs | 66 +++++++++++++++++-- docs/mcp.md | 4 +- 4 files changed, 103 insertions(+), 20 deletions(-) diff --git a/crates/engine/src/cmd/webexport.rs b/crates/engine/src/cmd/webexport.rs index 498982a7f9..a38d584966 100644 --- a/crates/engine/src/cmd/webexport.rs +++ b/crates/engine/src/cmd/webexport.rs @@ -340,11 +340,16 @@ pub struct ColorTable { type Shift = ([u8; 3], [u8; 3]); /// The most colours a colour table list holds. -const MAX_TABLE: usize = 256; +pub const MAX_TABLE: usize = 256; /// The error for a deletion that would leave the color table no color for the pixels. pub const KEEP_ONE: &str = "colorTable.deleted: at least one color has to stay in the color table"; +/// The error for a colour table list `what` (`colorTable.`) with more than [`MAX_TABLE`] colours. +pub fn too_many(what: &str) -> String { + format!("colorTable.{what}: at most {MAX_TABLE} colours") +} + impl ColorTable { /// Whether the table is a Custom one: a color was deleted or the palette is fixed. pub fn is_custom(&self) -> bool { @@ -353,7 +358,7 @@ impl ColorTable { fn colors(list: &[String], what: &str) -> std::result::Result, String> { if list.len() > MAX_TABLE { - return Err(format!("colorTable.{what}: at most {MAX_TABLE} colours")); + return Err(too_many(what)); } list.iter().map(|h| Self::rgb(h).ok_or_else(|| format!("colorTable.{what}: `{h}` is not a colour such as \"#ff8800\""))).collect() } diff --git a/crates/ui-egui/src/dialogs/save_for_web.rs b/crates/ui-egui/src/dialogs/save_for_web.rs index 7376973d6f..120025c416 100644 --- a/crates/ui-egui/src/dialogs/save_for_web.rs +++ b/crates/ui-egui/src/dialogs/save_for_web.rs @@ -154,6 +154,8 @@ fn settings_of(app: &VectorcraftApp, d: &Dialog) -> Result fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { let mut d = d.clone(); apply_preset(app, &mut d)?; + // A Color Picker OK the dialog has not drawn since still shifts its color. + take_shift(&mut d)?; let p = params(&d); // Done remembers the settings; Save… remembers them and writes the files. app.run("webExport.settings", p.clone())?; @@ -568,7 +570,9 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { { app.status(e); } - take_shift(d); + if let Err(e) = take_shift(d) { + app.status(e); + } let settings = settings_of(app, d); let mut browser = false; // In a window too narrow for both, the panes are narrower, so the settings beside them and the @@ -1447,22 +1451,29 @@ pub(super) fn edit_color(d: &mut Dialog, source: &str, start: &str) { *d = super::color_picker::over_effect(d, SHIFT_TO, c); } -/// Back from the Color Picker: its OK's color shifts the color it was opened for. -fn take_shift(d: &mut Dialog) { +/// Back from the Color Picker: its OK's color shifts the color it was opened for. An error is the +/// one [`shift_color`] gives. +fn take_shift(d: &mut Dialog) -> Result<(), String> { let source = d.fields.remove("__shiftSource"); if let (Some(to), Some(source)) = (d.fields.remove(SHIFT_TO), source) && let (Some(to), Some(source)) = (to.as_str(), source.as_str()) { - shift_color(d, source, to); + return shift_color(d, source, to); } + Ok(()) } /// Shift the source color `source` to `to` (`colorTable.shifted`), wherever it is in the image; it /// is no longer web-shifted. Picking the source color itself takes the shift away. The color -/// becomes the selection. Nothing changes when either is not a color. -pub(super) fn shift_color(d: &mut Dialog, source: &str, to: &str) { +/// becomes the selection. Nothing changes when either is not a color, and a new source when 256 +/// colors are already shifted is an error that changes nothing. +pub(super) fn shift_color(d: &mut Dialog, source: &str, to: &str) -> Result<(), String> { let hex = |h: &str| vectorcraft_color::Color::from_hex(h).map(|c| c.to_hex()); - let (Some(source), Some(to)) = (hex(source), hex(to)) else { return }; + let (Some(source), Some(to)) = (hex(source), hex(to)) else { return Ok(()) }; + let map = shifts(d); + if to != source && map.len() >= webexport::MAX_TABLE && !map.keys().any(|k| same_color(k, &source)) { + return Err(webexport::too_many("shifted")); + } unshift(d, &source); if to != source { let mut map = shifts(d); @@ -1472,6 +1483,7 @@ pub(super) fn shift_color(d: &mut Dialog, source: &str, to: &str) { toggle(d, "webShift", &source, false); d.fields.insert("__colors".into(), json!([source])); d.fields.insert("__color".into(), json!(source)); + Ok(()) } /// The `colorTable.shifted` field. @@ -1479,11 +1491,21 @@ fn shifts(d: &Dialog) -> Map { d.fields.get("colorTable").and_then(|t| t.get("shifted")).and_then(Value::as_object).cloned().unwrap_or_default() } -/// Take the shift by hand of the source color `source` away. +/// Whether `a` and `b` name one color, however each is written; text that is not a color matches +/// the same text in any case. +fn same_color(a: &str, b: &str) -> bool { + let rgb = |h: &str| vectorcraft_color::Color::from_hex(h).map(|c| c.to_hex()); + match (rgb(a), rgb(b)) { + (Some(a), Some(b)) => a == b, + _ => a.eq_ignore_ascii_case(b), + } +} + +/// Take the shift by hand of the source color `source` away: every key that names that color. pub(super) fn unshift(d: &mut Dialog, source: &str) { let mut map = shifts(d); let before = map.len(); - map.retain(|k, _| !k.eq_ignore_ascii_case(source)); + map.retain(|k, _| !same_color(k, source)); if map.len() != before { set_table(d, "shifted", Value::Object(map)); } @@ -1495,10 +1517,10 @@ pub(super) fn unshift_all_colors(d: &mut Dialog) { set_table(d, "webShift", json!([])); } -/// Add `color` to the colour table's `list`, or take it out. +/// Add `color` to the colour table's `list`, or take it out (every entry that names that color). pub(super) fn toggle(d: &mut Dialog, list: &str, color: &str, add: bool) { let mut v: Vec = d.fields.get("colorTable").and_then(|t| t.get(list)).and_then(Value::as_array).cloned().unwrap_or_default(); - v.retain(|c| !c.as_str().is_some_and(|c| c.eq_ignore_ascii_case(color))); + v.retain(|c| !c.as_str().is_some_and(|c| same_color(c, color))); if add { v.push(json!(color.to_ascii_lowercase())); } diff --git a/crates/ui-egui/src/dialogs/tests_save_for_web.rs b/crates/ui-egui/src/dialogs/tests_save_for_web.rs index 63ed3e2ded..b93c36def8 100644 --- a/crates/ui-egui/src/dialogs/tests_save_for_web.rs +++ b/crates/ui-egui/src/dialogs/tests_save_for_web.rs @@ -824,26 +824,58 @@ fn delete_color_skips_selected_colors_the_table_does_not_show() { fn colour_table_shift_unshift_and_unshift_all() { let mut d = Dialog::new(save_for_web::KIND, json!({})); save_for_web::toggle(&mut d, "webShift", "#123456", true); - save_for_web::shift_color(&mut d, "#123456", "#FF8800"); + save_for_web::shift_color(&mut d, "#123456", "#FF8800").unwrap(); assert_eq!(d.fields["colorTable"], json!({"webShift": [], "shifted": {"#123456": "#ff8800"}})); assert_eq!(save_for_web::selection(&d), ["#123456"]); // Not a color: nothing changes. let before = d.fields.clone(); - save_for_web::shift_color(&mut d, "nope", "#000000"); - save_for_web::shift_color(&mut d, "#123456", "nope"); + save_for_web::shift_color(&mut d, "nope", "#000000").unwrap(); + save_for_web::shift_color(&mut d, "#123456", "nope").unwrap(); assert_eq!(d.fields, before); - save_for_web::shift_color(&mut d, "#ABCDEF", "#00ff00"); - save_for_web::shift_color(&mut d, "#123456", "#123456"); + save_for_web::shift_color(&mut d, "#ABCDEF", "#00ff00").unwrap(); + save_for_web::shift_color(&mut d, "#123456", "#123456").unwrap(); assert_eq!(d.fields["colorTable"]["shifted"], json!({"#abcdef": "#00ff00"})); save_for_web::toggle(&mut d, "webShift", "#222222", true); save_for_web::unshift_all_colors(&mut d); assert_eq!((&d.fields["colorTable"]["shifted"], &d.fields["colorTable"]["webShift"]), (&json!({}), &json!([]))); let order: Vec = ["#000000", "#222222"].map(String::from).to_vec(); - save_for_web::shift_color(&mut d, "#222222", "#ffffff"); + save_for_web::shift_color(&mut d, "#222222", "#ffffff").unwrap(); save_for_web::delete_colors(&mut d, &order).unwrap(); assert_eq!((&d.fields["colorTable"]["shifted"], &d.fields["colorTable"]["deleted"]), (&json!({}), &json!(["#222222"]))); } +/// A key or list entry written another way (`#F00`, upper case) still names its color: a new shift +/// of that color replaces it, taking the shift away removes it, and a web shift of it is taken away. +#[test] +fn colour_table_shift_matches_a_color_written_another_way() { + let mut d = Dialog::new(save_for_web::KIND, json!({"colorTable": {"shifted": {"#F00": "#00ff00", "nope": "#000000"}, "webShift": ["#0000FF"]}})); + save_for_web::shift_color(&mut d, "#ff0000", "#123456").unwrap(); + assert_eq!(d.fields["colorTable"]["shifted"], json!({"#ff0000": "#123456", "nope": "#000000"})); + save_for_web::shift_color(&mut d, "#0000ff", "#654321").unwrap(); + assert_eq!(d.fields["colorTable"]["webShift"], json!([])); + save_for_web::unshift(&mut d, "#FF0000"); + assert_eq!(d.fields["colorTable"]["shifted"], json!({"#0000ff": "#654321", "nope": "#000000"})); +} + +/// With 256 colors shifted, shifting another color is refused and changes nothing; a shifted color +/// can still be shifted again or have its shift taken away. +#[test] +fn colour_table_shift_holds_at_most_256_colors() { + let full: serde_json::Map = (0..256).map(|i| (format!("#{i:06x}"), json!("#ffffff"))).collect(); + let mut d = Dialog::new(save_for_web::KIND, json!({"colorTable": {"shifted": full}, "__color": "#000001", "__colors": ["#000001"]})); + let before = d.fields.clone(); + let e = save_for_web::shift_color(&mut d, "#123456", "#000000").unwrap_err(); + assert_eq!((e.as_str(), &d.fields), ("colorTable.shifted: at most 256 colours", &before)); + save_for_web::shift_color(&mut d, "#000005", "#000000").unwrap(); + assert_eq!( + (d.fields["colorTable"]["shifted"]["#000005"].as_str(), d.fields["colorTable"]["shifted"].as_object().map(|m| m.len())), + (Some("#000000"), Some(256)) + ); + save_for_web::shift_color(&mut d, "#000005", "#000005").unwrap(); + save_for_web::shift_color(&mut d, "#123456", "#000000").unwrap(); + assert_eq!(d.fields["colorTable"]["shifted"]["#123456"], "#000000"); +} + /// One frame of `app` in `ctx`, 50 ms after the last. fn tick(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec) { let time = ctx.input(|i| i.time) + 0.05; @@ -943,6 +975,28 @@ fn dialog_set_edit_color_opens_the_color_picker() { assert_eq!((kind(&app), shifted), (Some(save_for_web::KIND), Some(json!({"#0000ff": "#00ff00"})))); } +/// Done right after the Color Picker's OK, before the dialog draws again, remembers the shift. +#[test] +fn done_right_after_the_color_picker_remembers_the_shift() { + let dir = vectorcraft_testkit::temp_dir("sfw-shift-done"); + let (mut app, _) = app(&dir, false); + app.run("shape.rectangle", json!({"x": 40, "y": 0, "width": 20, "height": 40})).unwrap(); + app.run("paint.setFill", json!({"color": "#0000ff"})).unwrap(); + app.run("file.saveForWeb", json!({})).unwrap(); + set(&mut app, "format", json!("gif")); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + set(&mut app, "__editColor", json!("#0000ff")); + tick(&mut app, &ctx, vec![]); + assert_eq!(picker_color(&app).as_deref(), Some("#0000ff")); + set(&mut app, "color", json!("#00ff00")); + confirm(&mut app).unwrap(); + set(&mut app, "discard", json!(true)); + confirm(&mut app).unwrap(); + let remembered = app.session.last_web_settings().color_table; + assert_eq!(remembered.shifted.get("#0000ff").map(String::as_str), Some("#00ff00")); +} + /// Lock, Transparent and Web Shift are off while the selected color (`__color`) is one the table /// no longer shows, so a click adds it to no list; with a color the table shows, Lock locks it. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index 85247a0c87..af2a1514ff 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -10567,7 +10567,9 @@ of a color shifted by hand. More than 256 entries, a key or value that is not a included), and two keys that name one color are errors. Presets and `webExport.settings` keep the map. In the dialog a double-click on an opaque swatch opens the Color Picker on the color shown (on the source color for a color already shifted; an agent sets `__editColor: "#source"`). Its OK shifts the color (picking the source color takes the shift away), and Cancel -leaves the table as it was. A shifted swatch shows the source color at its upper left and the new color at its lower +leaves the table as it was. An OK that would shift a 257th color changes nothing, and the status bar shows the +limit. A key written another way (`#F00`) still names its color, so a new shift or Unshift replaces it. Done or Save +right after the OK keeps the shift. A shifted swatch shows the source color at its upper left and the new color at its lower right, with the lock mark, and Lock stays on until the color is unshifted. Web Shift replaces a shift by hand, and Unshift All Colors in the table's menu clears `shifted` and `webShift`. Only Web Colors in the picker starts off. From 828f43447d19a46e0906d2e03421ae47591da4d7 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 09:15:20 -0800 Subject: [PATCH 08/26] Undo: a command run during a tool drag is its own undo step A command run from a panel, a menu or an automation client while a tool drag was open ran inside the drag. With Real-time Drawing on, the drag's next move put the document back to where the drag began and dropped the command's edit, and Escape dropped it too. With Real-time Drawing off, the release lost what the drag drew or moved. Such a command now runs on the document without the drag's preview and records its own undo step and journal entry. The drag then continues from the command's result: with Real-time Drawing on, its preview is applied again at once. 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 does not change what it moves, and the fill and stroke proxies keep showing those objects' paints. Objects the command deletes, hides or locks are left out of the drag. A change the command makes to the current layer or to the new-art paints stays when the drag ends or is canceled. When the command deletes the art being dragged, the drag records no step. A warning or an error from the preview applied again goes to the command's result. Commands that already kept the drag as a step first still do (Undo, Redo, command.batch, swatch.renameGroup, edit.newDocumentFromState and the others that call settle_interaction). Typing in progress is still kept as a step of its own first. A command run during a Quick Pen press, object.transform with copy during an Alt-drag, and a command run during a dialog's or a panel's preview still run inside the interaction. Docs: docs/mcp.md (undo / redo row), docs/target-app-parity.md. --- crates/engine/src/cmd/edit.rs | 5 +- crates/engine/src/cmd/swatch.rs | 2 +- crates/engine/src/interaction.rs | 59 +++ crates/engine/src/lib.rs | 5 +- crates/engine/src/session/documents.rs | 1 + crates/engine/src/session/edit.rs | 174 +++++++ crates/engine/src/session/execute.rs | 7 +- crates/engine/src/tests.rs | 1 + .../engine/src/tests/interaction_commands.rs | 485 ++++++++++++++++++ crates/engine/src/tooling.rs | 15 +- crates/ui-egui/src/tests.rs | 1 + crates/ui-egui/src/tests/drag_commands.rs | 48 ++ docs/mcp.md | 2 +- docs/target-app-parity.md | 1 + 14 files changed, 800 insertions(+), 6 deletions(-) create mode 100644 crates/engine/src/tests/interaction_commands.rs create mode 100644 crates/ui-egui/src/tests/drag_commands.rs diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index a20a6c47e4..fc31c86349 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -695,6 +695,7 @@ fn undo_group_end(s: &mut Session, p: &Value) -> Result { /// goes to the running command's result or the tool's status messages, as the tool's own commit /// reports it ([`Session::note_settled_warning`]). pub(crate) fn settle_interaction(s: &mut Session) -> Result<()> { + s.put_back_interaction(); let typing = typing_in_progress(s); match s.unapplied_interaction_preview().filter(|_| !s.previewing) { Some((cmd, p)) => match s.preview(&cmd, &p) { @@ -894,8 +895,10 @@ fn clear_history(s: &mut Session, _: &Value) -> Result { fn new_document_from_state(s: &mut Session, p: &Value) -> Result { const C: &str = "edit.newDocumentFromState"; let created = date_param(p, "created", C)?; + // The row as the panel lists it now, with a drag in progress on show: keeping it below + // changes the rows. + s.put_back_interaction(); let st = s.doc()?; - // The row as the panel lists it now: keeping an edit in progress below changes the rows. let chosen = match super::index_opt(p, "index", C)? { None => None, Some(row) => { diff --git a/crates/engine/src/cmd/swatch.rs b/crates/engine/src/cmd/swatch.rs index 511352b9a5..8137e561cf 100644 --- a/crates/engine/src/cmd/swatch.rs +++ b/crates/engine/src/cmd/swatch.rs @@ -1252,7 +1252,7 @@ fn swatch_rename_group(s: &mut Session, p: &Value) -> Result { return Err(bad(C, format!("a swatch or color group named `{name}` already exists"))); } // A drag still in progress is a step of its own, so canceling or undoing it leaves the rename. - if !s.previewing && s.batch_stash.is_none() && s.in_interaction() { + if !s.previewing && s.batch_stash.is_none() && (s.in_interaction() || s.holds_interaction()) { super::settle_interaction(s)?; } s.edit("Color Group Options", |d, _| { diff --git a/crates/engine/src/interaction.rs b/crates/engine/src/interaction.rs index 06cc86859e..a06c160897 100644 --- a/crates/engine/src/interaction.rs +++ b/crates/engine/src/interaction.rs @@ -8,6 +8,10 @@ pub struct Interaction { /// The selection the previews start from (shared, so a preview frame copies nothing). pub selection: Arc, pub preview: Option<(String, Value)>, + /// The active tool began it (a drag): a command from outside the tool runs as a step of its + /// own under it ([`crate::Session::outside_interaction`]). A dialog or a panel that begins an + /// interaction runs its commands inside it. + pub(crate) tool: bool, /// A replaced or canceled preview restores these new-art paints from before the interaction. pub(crate) paint: vectorcraft_tools::PaintDefaults, /// An accepted batch preview uses these final paints after changing the document color mode. @@ -35,6 +39,61 @@ pub struct Interaction { pub(crate) move_box: std::sync::OnceLock>, } +/// An interaction that a command from outside the tool set aside while it runs +/// ([`crate::Session::outside_interaction`]). +#[derive(Debug)] +pub(crate) struct HeldInteraction { + /// The [`crate::DocState::uid`] of the interaction's document. + pub(crate) uid: u64, + pub(crate) interaction: Interaction, + /// The document and the selection on show when the command began, when a preview had changed + /// them from the interaction's snapshot. + pub(crate) shown: Option<(Arc, Selection)>, + /// The document's current layer, highlighted Layers panel rows, highlighted variable and + /// isolation when the command began; a cancel puts back the ones it changed as it left them. + pub(crate) state: ViewState, + /// 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 per-document state an interaction puts back when it is canceled, besides the document and +/// the selection. +#[derive(Debug, PartialEq)] +pub(crate) struct ViewState { + pub(crate) active_layer: Option, + pub(crate) layer_rows: Vec, + pub(crate) variables_highlight: Option, + pub(crate) isolation: Option, +} + +impl ViewState { + pub(crate) fn of(st: &crate::DocState) -> Self { + ViewState { + active_layer: st.active_layer, + layer_rows: st.layer_rows.clone(), + variables_highlight: st.variables_highlight.clone(), + isolation: st.isolation, + } + } + + /// Give `it` the parts of `now` that differ from `self`, the state before a command. + pub(crate) fn rebase(&self, now: ViewState, it: &mut Interaction) { + if now.active_layer != self.active_layer { + it.active_layer = now.active_layer; + } + if now.layer_rows != self.layer_rows { + it.layer_rows = now.layer_rows; + } + if now.variables_highlight != self.variables_highlight { + it.variables_highlight = now.variables_highlight; + } + if now.isolation != self.isolation { + it.isolation = now.isolation; + } + } +} + /// What Object → Transform → Transform Again (⌘D) repeats ([`SessionState::last_transform`]). #[derive(Clone, Debug, PartialEq)] pub enum LastTransform { diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 68067dc697..472ae9c8f8 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -320,6 +320,9 @@ pub struct Session { /// The warnings of the previews that settling an interaction applied, while a top-level command /// or the tool's actions collect them ([`Session::collect_settled_warnings`]). settled_warnings: Option>, + /// The interaction a command from outside the tool set aside while it runs + /// ([`Session::outside_interaction`]). + held_interaction: Option, /// While [`Session::preview`] runs its command: its edits are the interaction's own. previewing: bool, /// The images Remove Background decoded during the interaction's preview steps, emptied when @@ -438,7 +441,7 @@ pub use error::{EngineError, READ_ONLY_LOCATION, Result, SCRIPT_BUSY}; #[cfg(test)] use history::history_budget_for; pub use history::{History, HistoryEntry, NamedStep, default_history_budget}; -pub(crate) use interaction::PreviewCopies; +pub(crate) use interaction::{HeldInteraction, PreviewCopies}; pub use interaction::{Interaction, LastTransform, UndoGroup, UndoScope}; pub use prefs::{DrawMode, KEY_HOLD_DELAY, KEY_HOLD_DELAY_RANGE, PluginBudget, Prefs}; pub use sanity::TOO_DEEP; diff --git a/crates/engine/src/session/documents.rs b/crates/engine/src/session/documents.rs index 1685adc40f..8e43a8ce34 100644 --- a/crates/engine/src/session/documents.rs +++ b/crates/engine/src/session/documents.rs @@ -137,6 +137,7 @@ impl Session { recovery: Default::default(), in_tool_actions: false, settled_warnings: None, + held_interaction: None, previewing: false, decoded_images: Default::default(), envelope_defaults: None, diff --git a/crates/engine/src/session/edit.rs b/crates/engine/src/session/edit.rs index e2ba1715b9..5930c8d9c0 100644 --- a/crates/engine/src/session/edit.rs +++ b/crates/engine/src/session/edit.rs @@ -260,6 +260,163 @@ impl Session { (r, settled) } + /// Run `f`, the top-level command `id` with `params` from outside the tool (a panel, a menu + /// item, an automation client), with the active document's tool drag set aside: the command + /// runs on the document the drag started from and records its own undo step and journal entry. + /// The drag then starts from what the command left, and its preview is applied again, so the + /// next preview, the commit and a cancel keep the command's edit, and Undo takes back the drag's + /// step before the command's. While the command runs, [`Session::in_interaction`] is false, so + /// it updates Recent Colors and converts or remaps the new-art paints at once, as it does with + /// no drag in progress. + /// + /// The interaction stays as it is, and the command runs inside it, for an interaction a dialog + /// or a panel 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 + /// it ends the path it draws), and for a copy made with `object.transform` during a drag that + /// copies (it copies the document as the drag's move left it). A command that settles, + /// commits or cancels the interaction, or that hands the active tool actions to apply, gets it + /// back first ([`Session::put_back_interaction`]), as it found it. + pub(crate) fn outside_interaction(&mut self, id: &str, params: &Value, f: impl FnOnce(&mut Self) -> Result) -> Result { + if cmd::typing_in_progress(self) || self.tool_id() == vectorcraft_tools::quickpen::ID { + return f(self); + } + let Some(st) = self.active_mut() else { return f(self) }; + let Some(it) = st.interaction.as_ref().filter(|it| it.tool) else { return f(self) }; + // A drag that copies: its latest preview, applied or held back by Real-time Drawing off, copies. + let copying = it.preview.as_ref().is_some_and(|(c, p)| c == "object.transform" && p.get("copy").and_then(Value::as_bool) == Some(true)); + if copying && id == "object.transform" && params.get("copy").and_then(Value::as_bool) == Some(true) { + return f(self); + } + let Some(interaction) = st.interaction.take() else { return f(self) }; + // The document and selection on show, when a preview changed them. + let previewed = !Arc::ptr_eq(&st.doc, &interaction.doc) || st.selection != *interaction.selection; + let shown = previewed.then(|| (st.doc.clone(), st.selection.clone())); + if previewed { + st.doc = interaction.doc.clone(); + st.selection.clone_from(&interaction.selection); + st.revision += 1; + cmd::globaledit::follow_history(st); + } + 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 }); + if previewed { + self.sync_front_profiles(); + } + let r = f(self); + self.put_back_interaction(); + r + } + + /// Put back the interaction [`Session::outside_interaction`] set aside. When the command left + /// the document and the selection as it found them, the preview on show before it is on show + /// again. Otherwise the interaction starts from the document the command left and from its + /// own selection, without the objects the command removed, hid or locked, and the preview that Real-time + /// Drawing showed is applied to it again. The warning or the error of that preview goes to + /// the command's result ([`Session::note_settled_warning`]); a preview that fails leaves the + /// interaction with nothing to commit. An interaction whose document the command closed ends, + /// and a document the command left an interaction of its own on keeps that one. + 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 }; + // 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 self.paint != paint + && let Some(st) = self.active_mut().filter(|d| d.uid == uid && d.interaction.is_none()) + { + let own = drag_selection(&it.selection, &st.doc); + if st.selection != own { + let made = std::mem::replace(&mut st.selection, own); + self.inherit_new_art(); + self.load_selection_paints(); + if let Some(st) = self.active_mut() { + st.selection = made; + } + } + } + // A change the command made to the new-art paints stays when the next preview or a cancel + // puts back the paints the interaction began with (the Live Paint Bucket's colors); the + // parts it left alone keep the interaction's. + let (now, start) = (&self.paint, &mut it.paint); + if now.fill != paint.fill { + start.fill.clone_from(&now.fill); + } + if now.stroke != paint.stroke { + start.stroke.clone_from(&now.stroke); + } + if now.stroke_width != paint.stroke_width { + start.stroke_width = now.stroke_width; + } + if now.appearance != paint.appearance { + start.appearance.clone_from(&now.appearance); + } + if now.opacity != paint.opacity { + start.opacity = now.opacity; + } + if now.blend != paint.blend { + start.blend = now.blend; + } + if now.style != paint.style { + start.style.clone_from(&now.style); + } + if now.inherited != paint.inherited { + start.inherited = now.inherited; + } + let active = self.active().is_some_and(|d| d.uid == uid); + let Some(st) = self.docs.iter_mut().find(|d| d.uid == uid) else { return }; + if st.interaction.is_some() { + return; + } + // A change the command made to the current layer, the highlighted rows or variable, or + // 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 { + if let Some((doc, selection)) = shown { + st.doc = doc; + st.selection = selection; + st.revision += 1; + cmd::globaledit::follow_history(st); + } + st.interaction = Some(it); + if previewed { + self.sync_front_profiles(); + } + return; + } + it.doc = st.doc.clone(); + // The drag acts on the objects it began with: a selection the command made (a paste, a + // duplicate, Select All) does not change what the drag moves. + it.selection = Arc::new(drag_selection(&it.selection, &st.doc)); + it.copies = None; + it.move_box = std::sync::OnceLock::new(); + // With Real-time Drawing off the preview waits for the commit, as it did before the command. + let again = it.preview.clone().filter(|_| previewed && active); + // Without a preview to apply, the drag's own selection is on show, as a preview would leave + // it before it acts. + if again.is_none() && st.selection != *it.selection { + st.selection.clone_from(&it.selection); + st.revision += 1; + } + st.interaction = Some(it); + self.clear_deferred_overlay_cache(); + if let Some((cmd, p)) = again { + match self.preview(&cmd, &p) { + Ok(v) => { + if let Some(w) = v.get("warning").and_then(Value::as_str) { + self.note_settled_warning(w); + } + } + Err(e) => self.note_settled_warning(&e.to_string()), + } + } + } + + /// While a command from outside the tool runs: the interaction it set aside + /// ([`Session::outside_interaction`]). + pub(crate) fn holds_interaction(&self) -> bool { + self.held_interaction.is_some() + } + /// [`Session::begin_interaction`] for a dialog or a panel that starts a preview → the warnings /// of the preview that keeping typing in progress applied, for its status bar. pub fn begin_interaction_warned(&mut self, label: &str) -> Result> { @@ -284,6 +441,8 @@ impl Session { if label != "Typing" && cmd::typing_in_progress(self) { cmd::settle_interaction(self)?; } + // A command from outside the tool that begins an interaction during a drag joins the drag's. + self.put_back_interaction(); // An edit the tool computes on another thread (a Shape Builder merge) is applied first too, // so the snapshot the interaction previews from and goes back to holds it. if !self.in_interaction() { @@ -300,6 +459,7 @@ impl Session { doc: st.doc.clone(), selection: Arc::new(st.selection.clone()), preview: None, + tool: false, paint, preview_paint: None, color_mode_paints: None, @@ -318,6 +478,7 @@ impl Session { /// Re-apply `cmd` on top of the interaction snapshot (replacing the previous preview). pub fn preview(&mut self, cmd: &str, params: &Value) -> Result { + self.put_back_interaction(); if self.script_running() { return Err(EngineError::Busy); } @@ -392,6 +553,7 @@ impl Session { pub fn commit_interaction(&mut self) -> Result<()> { self.clear_deferred_overlay_cache(); self.decoded_images.empty(); + self.put_back_interaction(); if let Some(paint) = self.active().and_then(|st| st.interaction.as_ref()).and_then(|it| it.preview_paint.clone()) { self.paint = paint; } @@ -481,6 +643,7 @@ impl Session { } pub fn cancel_interaction(&mut self) -> Result<()> { + self.put_back_interaction(); self.clear_deferred_overlay_cache(); self.decoded_images.empty(); self.pending_paint = None; @@ -512,3 +675,14 @@ impl Session { self.active().is_some_and(|d| d.interaction.is_some()) } } + +/// 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 { + let mut selection = began.clone(); + selection.prune(doc); + let editable = doc.editable(); + let held: Vec<_> = selection.objects.iter().copied().filter(|&id| !editable(id)).collect(); + selection.remove_all(held); + selection +} diff --git a/crates/engine/src/session/execute.rs b/crates/engine/src/session/execute.rs index 046c480079..ac987a83be 100644 --- a/crates/engine/src/session/execute.rs +++ b/crates/engine/src/session/execute.rs @@ -75,10 +75,15 @@ impl Session { self.finish_tool_edit_later()?; } let outer = std::mem::replace(&mut self.reading, !spec.journal || JOURNALED_READS.contains(&id)); + // A command from outside the tool, while the tool's drag is in progress, is a step of its + // own before the drag's ([`Session::outside_interaction`]). + let outside = spec.journal && !self.previewing && !self.in_tool_actions; // A preview that a top-level command applied first (a drag with Real-time Drawing off, kept // before Undo) reports its warning in the command's result. let r = if self.depth == 0 { - let (r, settled) = self.collect_settled_warnings(|s| s.execute_spec(spec, id, params)); + let (r, settled) = self.collect_settled_warnings(|s| { + if outside { s.outside_interaction(id, params, |s| s.execute_spec(spec, id, params)) } else { s.execute_spec(spec, id, params) } + }); r.map(|v| with_settled_warnings(v, &settled)) } else { self.execute_spec(spec, id, params) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index e524d1c63c..de919c224a 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -87,6 +87,7 @@ mod history_document; mod history_mem; mod ids_without_selection; mod inline; +mod interaction_commands; mod interactivity; mod interpolate_handles; mod intertwine; diff --git a/crates/engine/src/tests/interaction_commands.rs b/crates/engine/src/tests/interaction_commands.rs new file mode 100644 index 0000000000..e18b0db56d --- /dev/null +++ b/crates/engine/src/tests/interaction_commands.rs @@ -0,0 +1,485 @@ +//! A command run from outside the tool (a panel, a menu item, an automation client) while a tool's drag is +//! in progress is a step of its own, before the drag's: the drag's next preview, its release and +//! Escape keep the command's edit, and the release still draws what the drag drew, with Real-time +//! Drawing on and off. + +use serde_json::json; +use vectorcraft_geom::Rect; +use vectorcraft_tools::{Mods, PointerEvent, PointerKind, ToolKey}; + +use crate::*; + +/// The view the gestures run in: page coordinates, with Smart Guides off so nothing snaps. +fn view() -> ViewInfo { + ViewInfo { smart_guides: false, ..ViewInfo::default() } +} + +/// Feed the pointer event `(kind, x, y)` to the active tool. +fn pointer(s: &mut Session, kind: PointerKind, x: f64, y: f64) { + s.pointer(&PointerEvent::new(kind, x, y), view()).unwrap(); +} + +/// A new 400 × 400 pt document with Real-time Drawing `real_time`, holding one 20 × 20 pt rectangle +/// (returned), nothing selected, and the Rectangle tool chosen. +fn session(real_time: bool) -> (Session, NodeId) { + let mut s = Session::new(); + s.prefs.real_time_drawing = real_time; + s.execute("file.new", &json!({"width": 400, "height": 400})).unwrap(); + s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); + let other = s.doc().unwrap().selection.objects[0]; + s.execute("select.none", &json!({})).unwrap(); + s.select_tool("rectangle", view()).unwrap(); + (s, other) +} + +fn visible(s: &Session, id: NodeId) -> bool { + s.doc().unwrap().doc.node(id).expect("the object is in the document").visible +} + +/// The objects of the document's first layer. +fn objects(s: &Session) -> usize { + s.doc().unwrap().doc.layers[0].children().map_or(0, Vec::len) +} + +/// The commands journaled from entry `start` on. +fn journaled(s: &Session, start: usize) -> Vec { + s.journal.iter().skip(start).map(|(id, _)| id.clone()).collect() +} + +#[test] +fn a_command_during_a_drag_is_a_step_of_its_own_before_the_drag() { + for real_time in [true, false] { + let (mut s, other) = session(real_time); + let (steps, start) = (s.doc().unwrap().history.undo.len(), s.journal.len()); + pointer(&mut s, PointerKind::Down, 100.0, 100.0); + pointer(&mut s, PointerKind::Drag, 150.0, 150.0); + s.execute("object.hide", &json!({"ids": [other.0]})).unwrap(); + assert!(!visible(&s, other), "real time {real_time}: the command hides the object at once"); + pointer(&mut s, PointerKind::Drag, 200.0, 180.0); + assert!(!visible(&s, other), "real time {real_time}: the drag's next preview keeps the command's edit"); + pointer(&mut s, PointerKind::Up, 200.0, 180.0); + assert!(!visible(&s, other), "real time {real_time}: the release keeps the command's edit"); + assert_eq!(objects(&s), 2, "real time {real_time}: the release draws the rectangle"); + let drawn = s.doc().unwrap().selection.objects[0]; + assert_ne!(drawn, other); + assert_eq!(s.doc().unwrap().doc.bounds_of(&[drawn], false), Some(Rect::new(100.0, 100.0, 200.0, 180.0)), "real time {real_time}"); + assert_eq!(s.doc().unwrap().history.undo.len(), steps + 2, "real time {real_time}: the command and the drag are a step each"); + assert_eq!(journaled(&s, start), ["object.hide", "shape.rectangle"], "real time {real_time}"); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(objects(&s), 1, "real time {real_time}: Undo takes back the drawn rectangle"); + assert!(!visible(&s, other), "real time {real_time}: and leaves the command's edit"); + s.execute("edit.undo", &json!({})).unwrap(); + assert!(visible(&s, other), "real time {real_time}: the next Undo takes back the command's edit"); + } +} + +#[test] +fn escape_after_a_command_during_a_drag_keeps_the_command() { + for real_time in [true, false] { + let (mut s, other) = session(real_time); + let steps = s.doc().unwrap().history.undo.len(); + pointer(&mut s, PointerKind::Down, 100.0, 100.0); + pointer(&mut s, PointerKind::Drag, 150.0, 150.0); + s.execute("object.hide", &json!({"ids": [other.0]})).unwrap(); + s.tool_key(ToolKey::Escape, Mods::default(), view()).unwrap(); + pointer(&mut s, PointerKind::Up, 150.0, 150.0); + assert!(!visible(&s, other), "real time {real_time}: Escape takes back only the drag"); + assert_eq!(objects(&s), 1, "real time {real_time}: nothing is drawn"); + assert_eq!(s.doc().unwrap().history.undo.len(), steps + 1, "real time {real_time}"); + s.execute("edit.undo", &json!({})).unwrap(); + assert!(visible(&s, other), "real time {real_time}"); + } +} + +/// Every object of the first layer but `other`, as the document has it. +fn others(s: &Session, other: NodeId) -> Vec { + let d = &s.doc().unwrap().doc; + d.layers[0].children().map_or_else(Vec::new, |c| c.iter().filter(|n| n.id != other).map(|n| (**n).clone()).collect()) +} + +/// A new 400 × 400 pt document with Real-time Drawing `real_time`, holding a 40 × 40 pt square at +/// (100, 100) and a 20 × 20 pt one at (10, 10) → the session, the larger square (selected) and the +/// smaller one. +fn two_squares(real_time: bool) -> (Session, NodeId, NodeId) { + let mut s = Session::new(); + s.prefs.real_time_drawing = real_time; + s.execute("file.new", &json!({"width": 400, "height": 400})).unwrap(); + s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); + let other = s.doc().unwrap().selection.objects[0]; + s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 40, "height": 40})).unwrap(); + let target = s.doc().unwrap().selection.objects[0]; + (s, target, other) +} + +/// A press at the first point of `pts`, drags to the others and a release at the last, with +/// `mid` run after the first drag. +fn drag_with(s: &mut Session, pts: &[(f64, f64)], mid: impl FnOnce(&mut Session)) { + let (&(x0, y0), rest) = pts.split_first().expect("a press"); + pointer(s, PointerKind::Down, x0, y0); + let mut mid = Some(mid); + for &(x, y) in rest { + pointer(s, PointerKind::Drag, x, y); + if let Some(f) = mid.take() { + f(s); + } + } + let &(x, y) = pts.last().expect("a release"); + pointer(s, PointerKind::Up, x, y); +} + +/// Is `id` filled red? +fn red(s: &Session, id: NodeId) -> bool { + s.doc().unwrap().doc.node(id).and_then(|n| n.appearance.fill_paint().color()).is_some_and(|c| c.to_hex() == "#ff0000") +} + +/// The Selection tool's move, the Scale and Rotate tools and the Pen, each with a command that +/// fills another object red during the drag: the release keeps both, as two undo steps, and Undo +/// takes back the drag first. +#[test] +fn the_move_scale_rotate_and_pen_drags_keep_a_command_run_during_them() { + let drags: [(&str, &[(f64, f64)]); 4] = [ + ("selection", &[(120.0, 120.0), (140.0, 130.0), (170.0, 150.0)]), + ("scale", &[(150.0, 150.0), (170.0, 170.0), (190.0, 190.0)]), + ("rotate", &[(160.0, 120.0), (150.0, 150.0), (120.0, 160.0)]), + ("pen", &[(300.0, 300.0), (320.0, 300.0), (350.0, 320.0)]), + ]; + for (tool, pts) in drags { + for real_time in [true, false] { + let at = format!("{tool}, real time {real_time}"); + let (mut s, _, other) = two_squares(real_time); + if tool == "pen" { + s.execute("select.none", &json!({})).unwrap(); + } + s.select_tool(tool, view()).unwrap(); + let (before, steps) = (others(&s, other), s.doc().unwrap().history.undo.len()); + drag_with(&mut s, pts, |s| { + s.execute("paint.setFill", &json!({"ids": [other.0], "color": "#ff0000"})).unwrap(); + }); + assert!(!s.in_interaction(), "{at}"); + assert!(red(&s, other), "{at}: the release keeps the command's edit"); + assert_ne!(others(&s, other), before, "{at}: the release keeps the drag's edit"); + assert_eq!(s.doc().unwrap().history.undo.len(), steps + 2, "{at}"); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(others(&s, other), before, "{at}: Undo takes back the drag"); + assert!(red(&s, other), "{at}: and leaves the command's edit"); + s.execute("edit.undo", &json!({})).unwrap(); + assert!(!red(&s, other), "{at}: the next Undo takes back the command's edit"); + } + } +} + +/// A command that changes the object being moved: the move applies to the changed object. +#[test] +fn a_move_drag_moves_the_object_as_a_command_during_it_changed_it() { + for real_time in [true, false] { + let (mut s, target, _) = two_squares(real_time); + s.select_tool("selection", view()).unwrap(); + let fill = |s: &Session| s.doc().unwrap().doc.node(target).unwrap().appearance.fill_paint().color().map(|c| c.to_hex()); + let was = fill(&s); + drag_with(&mut s, &[(120.0, 120.0), (140.0, 130.0), (170.0, 150.0)], |s| { + s.execute("paint.setFill", &json!({"ids": [target.0], "color": "#ff0000"})).unwrap(); + }); + let moved = s.doc().unwrap().doc.bounds_of(&[target], false); + assert_eq!(moved, Some(Rect::new(150.0, 130.0, 190.0, 170.0)), "real time {real_time}"); + assert_eq!(fill(&s).as_deref(), Some("#ff0000"), "real time {real_time}"); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(s.doc().unwrap().doc.bounds_of(&[target], false), Some(Rect::new(100.0, 100.0, 140.0, 140.0)), "real time {real_time}"); + assert_eq!(fill(&s).as_deref(), Some("#ff0000"), "real time {real_time}: the fill is a step of its own"); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(fill(&s), was, "real time {real_time}"); + } +} + +/// A command that deletes the object being moved: the drag goes on and ends without an edit of +/// its own, on release and on Escape, and the deletion stays. +#[test] +fn a_move_drag_of_an_object_a_command_deleted_ends_without_an_edit() { + for (real_time, escape) in [(true, false), (false, false), (true, true), (false, true)] { + let at = format!("real time {real_time}, Escape {escape}"); + let (mut s, target, other) = two_squares(real_time); + s.select_tool("selection", view()).unwrap(); + let steps = s.doc().unwrap().history.undo.len(); + pointer(&mut s, PointerKind::Down, 120.0, 120.0); + pointer(&mut s, PointerKind::Drag, 140.0, 130.0); + s.execute("edit.clear", &json!({"ids": [target.0]})).unwrap(); + assert!(s.doc().unwrap().doc.node(target).is_none(), "{at}"); + pointer(&mut s, PointerKind::Drag, 170.0, 150.0); + if escape { + s.tool_key(ToolKey::Escape, Mods::default(), view()).unwrap(); + } + pointer(&mut s, PointerKind::Up, 170.0, 150.0); + assert!(!s.in_interaction(), "{at}"); + assert!(s.doc().unwrap().doc.node(target).is_none(), "{at}: the deletion stays"); + assert_eq!(others(&s, other), [], "{at}"); + assert_eq!(s.doc().unwrap().history.undo.len(), steps + 1, "{at}: only the deletion is a step"); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(s.doc().unwrap().doc.bounds_of(&[target], false), Some(Rect::new(100.0, 100.0, 140.0, 140.0)), "{at}"); + } +} + +/// A command that hides or locks the object being moved: the object stays where it was and +/// unselected, and the drag ends without an edit of its own. +#[test] +fn a_move_drag_of_an_object_a_command_hid_or_locked_leaves_it_alone() { + for command in ["object.hide", "object.lock"] { + for real_time in [true, false] { + let at = format!("{command}, real time {real_time}"); + let (mut s, target, _) = two_squares(real_time); + s.select_tool("selection", view()).unwrap(); + let steps = s.doc().unwrap().history.undo.len(); + drag_with(&mut s, &[(120.0, 120.0), (140.0, 130.0), (170.0, 150.0)], |s| { + s.execute(command, &json!({"ids": [target.0]})).unwrap(); + }); + assert!(!s.in_interaction(), "{at}"); + assert_eq!(s.doc().unwrap().doc.bounds_of(&[target], false), Some(Rect::new(100.0, 100.0, 140.0, 140.0)), "{at}: not moved"); + assert!(!s.doc().unwrap().selection.objects.contains(&target), "{at}: not selected"); + assert_eq!(s.doc().unwrap().history.undo.len(), steps + 1, "{at}: only the command is a step"); + } + } +} + +/// The commands that end a drag first still do: Undo during a drag keeps the drag as a step and +/// takes it back, and `command.batch` and `swatch.renameGroup` keep it as a step before their own. +#[test] +fn undo_and_a_batch_during_a_drag_still_keep_the_drag_first() { + for real_time in [true, false] { + let (mut s, target, other) = two_squares(real_time); + s.select_tool("selection", view()).unwrap(); + pointer(&mut s, PointerKind::Down, 120.0, 120.0); + pointer(&mut s, PointerKind::Drag, 170.0, 150.0); + s.execute("edit.undo", &json!({})).unwrap(); + assert!(!s.in_interaction(), "real time {real_time}"); + assert_eq!(s.doc().unwrap().doc.bounds_of(&[target], false), Some(Rect::new(100.0, 100.0, 140.0, 140.0)), "real time {real_time}"); + s.execute("edit.redo", &json!({})).unwrap(); + assert_eq!(s.doc().unwrap().doc.bounds_of(&[target], false), Some(Rect::new(150.0, 130.0, 190.0, 170.0)), "real time {real_time}"); + pointer(&mut s, PointerKind::Up, 170.0, 150.0); + + let (mut s, target, other2) = two_squares(real_time); + assert_eq!(other, other2); + s.select_tool("selection", view()).unwrap(); + let steps = s.doc().unwrap().history.undo.len(); + pointer(&mut s, PointerKind::Down, 120.0, 120.0); + pointer(&mut s, PointerKind::Drag, 170.0, 150.0); + s.execute("command.batch", &json!({"commands": [{"command": "object.hide", "params": {"ids": [other.0]}}]})).unwrap(); + assert!(!s.in_interaction(), "real time {real_time}: the batch keeps the drag first"); + pointer(&mut s, PointerKind::Up, 170.0, 150.0); + assert_eq!(s.doc().unwrap().history.undo.len(), steps + 2, "real time {real_time}"); + s.execute("edit.undo", &json!({})).unwrap(); + assert!(visible(&s, other), "real time {real_time}: Undo takes back the batch first"); + assert_eq!(s.doc().unwrap().doc.bounds_of(&[target], false), Some(Rect::new(150.0, 130.0, 190.0, 170.0)), "real time {real_time}"); + + // A color group renamed during the drag keeps the drag as a step before the rename. + let (mut s, target, _) = two_squares(real_time); + s.select_tool("selection", view()).unwrap(); + let steps = s.doc().unwrap().history.undo.len(); + pointer(&mut s, PointerKind::Down, 120.0, 120.0); + pointer(&mut s, PointerKind::Drag, 170.0, 150.0); + s.execute("swatch.renameGroup", &json!({"group": "Brights", "name": "Vivid"})).unwrap(); + assert!(!s.in_interaction(), "real time {real_time}: the rename keeps the drag first"); + pointer(&mut s, PointerKind::Up, 170.0, 150.0); + assert_eq!(s.doc().unwrap().history.undo.len(), steps + 2, "real time {real_time}"); + s.execute("edit.undo", &json!({})).unwrap(); + assert!(s.doc().unwrap().doc.swatch_groups.iter().any(|g| g.name == "Brights"), "real time {real_time}: Undo takes back the rename"); + assert_eq!(s.doc().unwrap().doc.bounds_of(&[target], false), Some(Rect::new(150.0, 130.0, 190.0, 170.0)), "real time {real_time}"); + } +} + +/// A copy made with `object.transform` during an Alt-drag runs inside the drag, with Real-time +/// Drawing on and off: the release records one step that holds both. +#[test] +fn a_copy_during_an_alt_drag_is_part_of_the_drag() { + for real_time in [true, false] { + let (mut s, target, _) = two_squares(real_time); + s.select_tool("selection", view()).unwrap(); + let steps = s.doc().unwrap().history.undo.len(); + let alt = Mods { alt: true, ..Mods::default() }; + for (kind, x, y) in [(PointerKind::Down, 120.0, 120.0), (PointerKind::Drag, 170.0, 150.0)] { + s.pointer(&PointerEvent::new(kind, x, y).with_mods(alt), view()).unwrap(); + } + s.execute("object.transform", &json!({"matrix": [1, 0, 0, 1, 0, 60], "copy": true, "ids": [target.0]})).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Up, 170.0, 150.0).with_mods(alt), view()).unwrap(); + assert!(!s.in_interaction(), "real time {real_time}"); + assert_eq!(s.doc().unwrap().history.undo.len(), steps + 1, "real time {real_time}: one step for the drag and the copy"); + + // With Alt let go during the drag, the drag moves again, and the copy is a step of its own. + let (mut s, target, _) = two_squares(real_time); + s.select_tool("selection", view()).unwrap(); + let steps = s.doc().unwrap().history.undo.len(); + s.pointer(&PointerEvent::new(PointerKind::Down, 120.0, 120.0).with_mods(alt), view()).unwrap(); + s.pointer(&PointerEvent::new(PointerKind::Drag, 150.0, 140.0).with_mods(alt), view()).unwrap(); + pointer(&mut s, PointerKind::Drag, 170.0, 150.0); + s.execute("object.transform", &json!({"matrix": [1, 0, 0, 1, 0, 60], "copy": true, "ids": [target.0]})).unwrap(); + pointer(&mut s, PointerKind::Up, 170.0, 150.0); + assert_eq!(s.doc().unwrap().history.undo.len(), steps + 2, "real time {real_time}: the copy and the move"); + } +} + +/// A command that changes only the current layer during a drag keeps its change through Escape. +#[test] +fn escape_keeps_a_current_layer_set_during_a_drag() { + for real_time in [true, false] { + let (mut s, _) = session(real_time); + let first = s.doc().unwrap().active_layer; + let second = NodeId(s.execute("layer.new", &json!({})).unwrap()["id"].as_u64().unwrap()); + let first = first.expect("a current layer"); + s.execute("layer.setCurrent", &json!({"id": first.0})).unwrap(); + pointer(&mut s, PointerKind::Down, 100.0, 100.0); + pointer(&mut s, PointerKind::Drag, 150.0, 150.0); + s.execute("layer.setCurrent", &json!({"id": second.0})).unwrap(); + s.tool_key(ToolKey::Escape, Mods::default(), view()).unwrap(); + pointer(&mut s, PointerKind::Up, 150.0, 150.0); + assert_eq!(s.doc().unwrap().active_layer, Some(second), "real time {real_time}"); + } +} + +/// With Real-time Drawing on, the drag's preview is on show again right after the command. +#[test] +fn the_drag_preview_shows_again_after_the_command() { + let (mut s, other) = session(true); + pointer(&mut s, PointerKind::Down, 100.0, 100.0); + pointer(&mut s, PointerKind::Drag, 150.0, 150.0); + assert_eq!(objects(&s), 2, "the preview draws the rectangle"); + s.execute("object.hide", &json!({"ids": [other.0]})).unwrap(); + assert_eq!(objects(&s), 2, "the preview is on show after the command"); + s.execute("object.showAll", &json!({})).unwrap(); + assert_eq!(objects(&s), 2, "and after a second one"); + assert!(visible(&s, other)); + assert!(s.in_interaction()); + pointer(&mut s, PointerKind::Up, 150.0, 150.0); + assert_eq!(objects(&s), 2); + assert!(visible(&s, other)); +} + +/// A command that changes the selection during a move drag (Select All, Deselect, a duplicate) +/// leaves the drag moving the object it began with. +#[test] +fn a_selection_made_during_a_move_drag_leaves_the_drag_moving_its_object() { + for command in ["select.all", "select.none", "edit.duplicate"] { + for real_time in [true, false] { + let at = format!("{command}, real time {real_time}"); + let (mut s, target, other) = two_squares(real_time); + s.select_tool("selection", view()).unwrap(); + drag_with(&mut s, &[(120.0, 120.0), (140.0, 130.0), (170.0, 150.0)], |s| { + s.execute(command, &json!({})).unwrap(); + }); + let d = &s.doc().unwrap().doc; + assert_eq!(d.bounds_of(&[target], false), Some(Rect::new(150.0, 130.0, 190.0, 170.0)), "{at}: the drag moves its object"); + assert_eq!(d.bounds_of(&[other], false), Some(Rect::new(10.0, 10.0, 30.0, 30.0)), "{at}: and nothing else"); + if command == "edit.duplicate" { + let copies = others(&s, other).into_iter().filter(|n| n.id != target).map(|n| n.id).collect::>(); + assert_eq!(copies.len(), 1, "{at}"); + assert_eq!(d.bounds_of(&copies, false), Some(Rect::new(100.0, 100.0, 140.0, 140.0)), "{at}: the copy stays where it was made"); + } + } + } +} + +/// A command that selects another object during a move drag: the drag's object stays selected, +/// and the fill and stroke proxies keep showing its paints. +#[test] +fn a_selection_made_during_a_move_drag_leaves_the_paints_of_the_drag_object() { + for real_time in [true, false] { + let at = format!("real time {real_time}"); + let (mut s, target, other) = two_squares(real_time); + s.execute("paint.setFill", &json!({"ids": [target.0], "color": "#ff0000"})).unwrap(); + s.execute("paint.setFill", &json!({"ids": [other.0], "color": "#0000ff"})).unwrap(); + s.execute("select.none", &json!({})).unwrap(); + s.execute("select.set", &json!({"ids": [target.0]})).unwrap(); + s.select_tool("selection", view()).unwrap(); + let fill = |s: &Session| s.paint.fill.color().map(|c| c.to_hex()); + assert_eq!(fill(&s).as_deref(), Some("#ff0000"), "{at}"); + pointer(&mut s, PointerKind::Down, 120.0, 120.0); + pointer(&mut s, PointerKind::Drag, 140.0, 130.0); + s.execute("select.set", &json!({"ids": [other.0]})).unwrap(); + assert_eq!(s.doc().unwrap().selection.objects, [target], "{at}"); + assert_eq!(fill(&s).as_deref(), Some("#ff0000"), "{at}: after the command"); + pointer(&mut s, PointerKind::Drag, 170.0, 150.0); + pointer(&mut s, PointerKind::Up, 170.0, 150.0); + assert_eq!(s.doc().unwrap().selection.objects, [target], "{at}"); + assert_eq!(fill(&s).as_deref(), Some("#ff0000"), "{at}: after the release"); + } +} + +/// The Scale and Rotate tools and the Pen adding to a path, with a command that deletes the +/// object they act on during the drag: the drag ends without an edit of its own and the deletion +/// stays. +#[test] +fn a_scale_rotate_or_pen_drag_of_an_object_a_command_deleted_ends_without_an_edit() { + let drags: [(&str, &[(f64, f64)]); 3] = [ + ("scale", &[(150.0, 150.0), (170.0, 170.0), (190.0, 190.0)]), + ("rotate", &[(160.0, 120.0), (150.0, 150.0), (120.0, 160.0)]), + ("pen", &[(350.0, 350.0), (370.0, 360.0), (380.0, 380.0)]), + ]; + for (tool, pts) in drags { + for real_time in [true, false] { + let at = format!("{tool}, real time {real_time}"); + let (mut s, target, _) = two_squares(real_time); + s.select_tool(tool, view()).unwrap(); + let target = if tool == "pen" { + s.execute("select.none", &json!({})).unwrap(); + for (x, y) in [(300.0, 300.0), (350.0, 300.0)] { + pointer(&mut s, PointerKind::Down, x, y); + pointer(&mut s, PointerKind::Up, x, y); + } + s.doc().unwrap().selection.objects[0] + } else { + target + }; + let before = s.doc().unwrap().doc.clone(); + let steps = s.doc().unwrap().history.undo.len(); + drag_with(&mut s, pts, |s| { + s.execute("edit.clear", &json!({"ids": [target.0]})).unwrap(); + }); + assert!(!s.in_interaction(), "{at}"); + assert!(s.doc().unwrap().doc.node(target).is_none(), "{at}: the deletion stays"); + assert_eq!(s.doc().unwrap().history.undo.len(), steps + 1, "{at}: only the deletion is a step"); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(*s.doc().unwrap().doc, *before, "{at}: Undo brings the object back as it was"); + } + } +} + +/// With the Live Paint Bucket's Selection tool (Cmd+drag), a fill chosen during the drag stays the +/// new-art fill after the release and after Escape, though the drag puts back the bucket's colors +/// it began with. +#[test] +fn a_fill_chosen_during_a_bucket_drag_stays() { + for (real_time, escape) in [(true, false), (false, false), (true, true), (false, true)] { + let at = format!("real time {real_time}, Escape {escape}"); + let (mut s, _, _) = two_squares(real_time); + s.select_tool("livePaintBucket", view()).unwrap(); + let cmd = Mods { cmd: true, ..Mods::default() }; + for (kind, x, y) in [(PointerKind::Down, 120.0, 120.0), (PointerKind::Drag, 140.0, 130.0)] { + s.pointer(&PointerEvent::new(kind, x, y).with_mods(cmd), view()).unwrap(); + } + assert!(s.in_interaction(), "{at}: the lent Selection tool drags the square"); + s.execute("paint.setFill", &json!({"color": "#00ff00", "ids": []})).unwrap(); + let green = s.paint.fill.clone(); + s.pointer(&PointerEvent::new(PointerKind::Drag, 170.0, 150.0).with_mods(cmd), view()).unwrap(); + if escape { + s.tool_key(ToolKey::Escape, Mods::default(), view()).unwrap(); + } + s.pointer(&PointerEvent::new(PointerKind::Up, 170.0, 150.0).with_mods(cmd), view()).unwrap(); + assert_eq!(s.paint.fill, green, "{at}"); + } +} + +/// A command run during a Quick Pen press still runs inside the press, so it records no undo +/// step of its own while the press is held. +#[test] +fn a_command_during_a_quick_pen_press_runs_inside_it() { + for real_time in [true, false] { + let at = format!("real time {real_time}"); + let (mut s, other) = session(real_time); + s.select_tool(vectorcraft_tools::quickpen::ID, view()).unwrap(); + pointer(&mut s, PointerKind::Down, 50.0, 50.0); + pointer(&mut s, PointerKind::Up, 50.0, 50.0); + pointer(&mut s, PointerKind::Down, 100.0, 100.0); + pointer(&mut s, PointerKind::Drag, 150.0, 120.0); + assert!(s.in_interaction(), "{at}: the press drags a piece"); + let steps = s.doc().unwrap().history.undo.len(); + s.execute("object.hide", &json!({"ids": [other.0]})).unwrap(); + assert!(s.in_interaction(), "{at}"); + assert_eq!(s.doc().unwrap().history.undo.len(), steps, "{at}: no step of its own during the press"); + } +} diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rs index f3d615ac8d..6c0f83439e 100644 --- a/crates/engine/src/tooling.rs +++ b/crates/engine/src/tooling.rs @@ -1611,6 +1611,10 @@ impl Session { /// Apply tool actions. Errors from previews are reported but keep the interaction alive. pub fn apply_actions(&mut self, acts: Vec) -> Result> { + // The tool acts on its own interaction, which a command from outside it may have set aside. + if !acts.is_empty() { + self.put_back_interaction(); + } let outer = std::mem::replace(&mut self.in_tool_actions, true); let outer_bucket = self.back_to_bucket; // The Eyedropper's sample into a stop of the Live Paint Bucket's gradient, which switches back to the bucket. @@ -1636,7 +1640,16 @@ impl Session { let mut ui = vec![]; for a in acts { match a { - Action::Begin(label) => self.begin_interaction(&label)?, + Action::Begin(label) => { + // The snapshot of the interaction open before, which the tool's drag then joins. + let open = self.active().and_then(|st| st.interaction.as_ref()).map(|it| std::sync::Arc::as_ptr(&it.doc)); + self.begin_interaction(&label)?; + if let Some(it) = self.active_mut().and_then(|st| st.interaction.as_mut()) + && open != Some(std::sync::Arc::as_ptr(&it.doc)) + { + it.tool = true; + } + } Action::Preview(cmd, p) => { // Performance › Real-time Drawing and Editing (#394): off, remember the latest // params and apply them once on Commit instead of every move. A ruler guide diff --git a/crates/ui-egui/src/tests.rs b/crates/ui-egui/src/tests.rs index e0619ddaf7..30e5648f23 100644 --- a/crates/ui-egui/src/tests.rs +++ b/crates/ui-egui/src/tests.rs @@ -8,6 +8,7 @@ mod cut; mod distortkeys; mod docsetup; mod document_drag; +mod drag_commands; pub(super) mod folder; mod font_menu; mod fonts; diff --git a/crates/ui-egui/src/tests/drag_commands.rs b/crates/ui-egui/src/tests/drag_commands.rs new file mode 100644 index 0000000000..8879c3e25c --- /dev/null +++ b/crates/ui-egui/src/tests/drag_commands.rs @@ -0,0 +1,48 @@ +//! A command sent through the control channel (`engine.execute`, which MCP's `run_command` sends) +//! or run as a menu item while a tool's drag is in progress is a step of its own, before the drag's. + +use serde_json::{Value, json}; +use vectorcraft_engine::Session; + +use crate::VectorcraftApp; + +/// Send a control request → its reply. +fn control(app: &mut VectorcraftApp, ctx: &egui::Context, method: &str, params: Value) -> Value { + let (request, _) = crate::control::ControlRequest::new(method, params); + let crate::control::Outcome::Done(reply) = crate::control::handle(app, ctx, &request) else { panic!("{method}: not done") }; + reply +} + +#[test] +fn a_command_from_the_control_channel_or_a_menu_during_a_drag_is_a_step_of_its_own() { + for through_control in [true, false] { + let at = format!("control channel {through_control}"); + let mut app = VectorcraftApp::new(Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 400, "height": 400})).unwrap(); + let other = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap(); + app.run("select.none", json!({})).unwrap(); + app.select_tool("rectangle"); + let ctx = egui::Context::default(); + let objects = |app: &VectorcraftApp| app.session.doc().unwrap().doc.layers[0].children().map_or(0, Vec::len); + let hidden = |app: &VectorcraftApp| !app.session.doc().unwrap().doc.node(vectorcraft_doc::NodeId(other)).unwrap().visible; + let steps = app.session.doc().unwrap().history.undo.len(); + let down = json!({"events": [{"kind": "down", "x": 100, "y": 100}, {"kind": "drag", "x": 150, "y": 150}]}); + assert_eq!(control(&mut app, &ctx, "ui.pointer", down)["ok"], true, "{at}"); + if through_control { + let r = control(&mut app, &ctx, "engine.execute", json!({"command": "object.hide", "params": {"ids": [other]}})); + assert_eq!(r["ok"], true, "{at}: {r}"); + } else { + app.run("object.hide", json!({"ids": [other]})).unwrap(); + } + let up = json!({"events": [{"kind": "drag", "x": 200, "y": 180}, {"kind": "up", "x": 200, "y": 180}]}); + assert_eq!(control(&mut app, &ctx, "ui.pointer", up)["ok"], true, "{at}"); + assert!(hidden(&app), "{at}: the drag keeps the command's edit"); + assert_eq!(objects(&app), 2, "{at}: the drag draws its rectangle"); + assert_eq!(app.session.doc().unwrap().history.undo.len(), steps + 2, "{at}: a step each"); + app.run("edit.undo", json!({})).unwrap(); + assert_eq!(objects(&app), 1, "{at}: Undo takes back the drag first"); + assert!(hidden(&app), "{at}"); + app.run("edit.undo", json!({})).unwrap(); + assert!(!hidden(&app), "{at}: then the command"); + } +} diff --git a/docs/mcp.md b/docs/mcp.md index 3c577e0356..0759644cc3 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -758,7 +758,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`. 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` 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: diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 3da663c191..e3968f2379 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -763,6 +763,7 @@ since 2026-10-01. - **Mirrored handles in a Direct Selection drag (#7842):** Cmd/Ctrl added after a handle drag begins puts the anchor's other handle opposite the dragged one at the same length, on paths, type on a path and blend spines, and the anchor keeps its kind; Shift constrains the dragged handle first, and Alt keeps the handles independent. At an open end, where no segment leaves the anchor on the other side, the handle moves as it does without Cmd/Ctrl. When Cmd/Ctrl lends Direct Selection for the gesture while another tool, such as the Pen, is chosen, that press does not mirror; letting it go and pressing it again during the drag does. This is VectorCraft's own behavior. Regression tests: `crates/engine/tests/direct_handle_mirror.rs`. - **Cut of picked anchors (#6361):** Edit › Cut removes direct-selected anchors from their path and from a compound path's member, with the segments attached to them, as Clear does. Picked segments still lose only those segments. When a path also has a picked segment, Cut removes and copies only its picked segments and ignores its picked anchors, on every contour, as Clear does; an anchor left without a surviving segment is removed with them. Regression tests: `cut_*_anchors_*` and `cut_of_an_anchor_with_a_segment_on_another_contour_leaves_the_source_as_clear_does` in `crates/engine/tests/it/copy_direct_selection.rs`. - **Escape in Selection tool drags:** Escape during a Selection tool move or Alt-drag copy, a bounding-box scale or rotation, a marquee, or a corner widget, pie widget or bracket drag cancels it: the art returns to its state at the press, no copy is left, no undo step is added, the release does nothing, and the tool stays chosen. This is VectorCraft's own behavior. Regression tests: `escape_cancels_*` in `select/tests.rs` and `pie.rs`, and `escape_cancels_a_selection_tool_move_copy_scale_or_rotation` in `tests/selectescape.rs`. +- **Commands run during a tool drag:** by VectorCraft's own rule, a command that changes the document while a tool drag is in progress (from a panel, a menu or `run_command`) records its own undo step before the drag's. The drag goes on with the art the command left, Escape cancels only the drag, and Undo takes back the drag first and the command next, with Real-time Drawing on or off. A selection the command makes does not change which objects the drag moves. Commands that keep the drag as a step first (Undo, Redo, `command.batch` and others), a Quick Pen press, and a copy made with `object.transform` during an Alt-drag work as before. Regression tests: `crates/engine/src/tests/interaction_commands.rs` and `tests::drag_commands` in `crates/ui-egui`. - **Large Shift-marquee selections and Select › Inverse:** `select.toggle` and `select.add` with many ids (a Shift-drag marquee sends them together) go through the selection once instead of once per id, and Select › Inverse looks each object up in a set of the selected ones. The resulting selection, its order and the reply are the same as before. With 50,000 objects the selection step of toggling every object off took 528 to 655 ms before and 2.5 to 4.6 ms after in 7 runs, wall clock on a machine that was running other builds (`cargo run --release -p vectorcraft-engine --example selection_bench`). Regression tests: `add_all_does_what_adding_each_does` and `toggle_all_does_what_toggling_each_does` in `crates/doc/src/selection/tests.rs`, and `toggle_and_add_handle_each_listed_id_in_order` in `crates/engine/tests/it/selection_commands.rs`. - **Shift-click in the Layers panel's selection column on a large layer:** `layer.selectAll {id, add: true}` checks whether the row's art is all selected with a set of the selected objects, and removes or adds that art in one pass instead of once per object. The resulting selection, its order, the reply and the highlighted rows are the same as before. On a layer of 50,000 objects the whole command took a median of 733 ms before and 6.9 ms after when all of the layer's art was selected, and 369 ms before and 24 ms after when every other object was, in 7 runs each, wall clock on Linux while other builds were running (`cargo run --release -p vectorcraft-engine --example layer_select_bench`). Regression test: `a_shift_click_in_the_selection_column_matches_adding_or_removing_each_id` in `crates/engine/src/tests/layers.rs`. - **Ctrl/Cmd-click and Shift-click on Layers panel target circles (#8639):** the target circles follow the same modifier rules as the row names, as the help page describes for selecting objects in the Layers panel: Shift for adjacent objects, Ctrl or Command for non-adjacent ones ([Move objects to different layers](https://helpx.adobe.com/illustrator/desktop/manage-layers/create-and-organize-layers/move-objects-to-different-layers.html)). Ctrl/Cmd-click adds the item (a layer: its art) to the selection or takes it out, which Shift-click did before (#913); Shift-click selects the art of every row from the last circle clicked (else the targeted row) to this one, and Shift+Ctrl/Cmd-click adds it (`layer.target {range, add?}`). Hidden or locked art and art outside the isolated group in the range is left out, and nothing stays targeted. Regression tests: `clicking_a_target_circle_targets_the_layer` and `shift_clicking_a_target_circle_selects_a_range_of_rows` in `crates/ui-egui/src/panels/layers/tests.rs`. From c0f91bc8203dbdce1ffd840065d8c489b741aa7f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 09:17:09 -0800 Subject: [PATCH 09/26] Save for Web: the color table's selection matches a color written another way - A selected color or list entry written another way (`#00F` for `#0000ff`) now names its table color: Lock, Transparent, Web Shift and Delete Color act on it and write it as the table does, and the ring and button labels follow it. - Delete Color compares the table's lists as colors, so deleting the only color left is refused when the selection or a list is written another way, and a deleted color is taken out of the Lock, Transparent and Web Shift lists however they write it. - A Ctrl-click on a selected color takes out every selection entry that names it. - A spelling with alpha (`#rrggbbaa`) names no table color, as the engine reads the table. Docs: docs/mcp.md. --- crates/ui-egui/src/dialogs/save_for_web.rs | 66 ++++++++++------ .../ui-egui/src/dialogs/tests_save_for_web.rs | 76 +++++++++++++++++++ docs/mcp.md | 4 +- 3 files changed, 123 insertions(+), 23 deletions(-) diff --git a/crates/ui-egui/src/dialogs/save_for_web.rs b/crates/ui-egui/src/dialogs/save_for_web.rs index 120025c416..4ba055b558 100644 --- a/crates/ui-egui/src/dialogs/save_for_web.rs +++ b/crates/ui-egui/src/dialogs/save_for_web.rs @@ -1219,7 +1219,7 @@ fn color_table(ui: &mut egui::Ui, d: &mut Dialog, s: Option<&WebSettings>) -> Re } // The transparent entry itself isn't a colour to edit. let pickable = !c.transparent || *mapped; - let ringed = pickable && picked.iter().any(|h| h.eq_ignore_ascii_case(&hex(c.source))); + let ringed = pickable && picked.iter().any(|h| same_color(h, &hex(c.source))); p.rect_stroke(r, 0.0, egui::Stroke::new(if ringed { 2.0 } else { 1.0 }, if ringed { t.accent } else { t.border }), egui::StrokeKind::Outside); if !pickable { continue; @@ -1242,14 +1242,17 @@ fn color_table(ui: &mut egui::Ui, d: &mut Dialog, s: Option<&WebSettings>) -> Re d.fields.insert("__editColor".into(), json!(source)); d.fields.insert("__editStart".into(), json!(start)); } - let shifted = |c: &str| table.shifted.keys().any(|k| k.eq_ignore_ascii_case(c)); + let shifted = |c: &str| table.shifted.keys().any(|k| same_color(k, c)); // The colors the table shows, by source: Lock, Transparent, Web Shift and Delete Color act only // on these. let palette: Vec = shot.colors.iter().filter(|c| !c.transparent).map(|c| hex(c.source)).chain(shot.mapped.iter().map(|c| hex(*c))).collect(); - let shown = palette.iter().any(|p| p.eq_ignore_ascii_case(&selected)); + // The selected color as the table writes it; the buttons act on that spelling. + let shown_as = palette.iter().find(|p| same_color(p, &selected)).map(|p| p.to_ascii_lowercase()); + let shown = shown_as.is_some(); + let selected = shown_as.unwrap_or(selected); ui.add_space(4.0); - let on = |list: &[String]| list.iter().any(|h| h.eq_ignore_ascii_case(&selected)); + let on = |list: &[String]| list.iter().any(|h| same_color(h, &selected)); ui.horizontal(|ui| { ui.add_enabled_ui(shown, |ui| { for (list, on_label, off_label) in [ @@ -1320,9 +1323,18 @@ fn color_table(ui: &mut egui::Ui, d: &mut Dialog, s: Option<&WebSettings>) -> Re Ok(()) } -/// The selected colors (by source) that `palette`, the colors the table shows, holds. +/// The selected colors (by source) that `palette`, the colors the table shows, holds, each as +/// `palette` writes it, once. pub(super) fn selected_in(d: &Dialog, palette: &[String]) -> Vec { - selection(d).into_iter().filter(|c| palette.iter().any(|p| p.eq_ignore_ascii_case(c))).collect() + let mut out: Vec = Vec::new(); + for c in selection(d) { + if let Some(p) = palette.iter().find(|p| same_color(p, &c)).map(|p| p.to_ascii_lowercase()) + && !out.contains(&p) + { + out.push(p); + } + } + out } /// The colour table's selected colors, by source: `__colors`, else `__color`. @@ -1342,7 +1354,7 @@ pub(super) fn selection(d: &Dialog) -> Vec { /// or taken out, and the anchor moves to the last color left in the selection. pub(super) fn pick(d: &mut Dialog, order: &[String], color: &str, shift: bool, command: bool) { let color = color.to_ascii_lowercase(); - let at = |c: &str| order.iter().position(|o| o.eq_ignore_ascii_case(c)); + let at = |c: &str| order.iter().position(|o| same_color(o, c)); if shift && let (Some(a), Some(b)) = (at(&d.str("__color")), at(&color)) { let range: Vec = order[a.min(b)..=a.max(b)].iter().map(|c| c.to_ascii_lowercase()).collect(); d.fields.insert("__colors".into(), json!(range)); @@ -1350,15 +1362,13 @@ pub(super) fn pick(d: &mut Dialog, order: &[String], color: &str, shift: bool, c } let mut set = selection(d); let anchor = if command { - match set.iter().position(|c| *c == color) { - Some(i) => { - set.remove(i); - set.last().cloned() - } - None => { - set.push(color.clone()); - Some(color) - } + if set.iter().any(|c| same_color(c, &color)) { + // Every entry that names the color, however it is written. + set.retain(|c| !same_color(c, &color)); + set.last().cloned() + } else { + set.push(color.clone()); + Some(color) } } else { set = vec![color.clone()]; @@ -1384,6 +1394,9 @@ pub(super) fn delete_colors(d: &mut Dialog, palette: &[String]) -> Result<(), St d.fields.remove("__color"); return Ok(()); } + // Each entry as `#rrggbb` when it names a color, so entries written another way compare equal. + let norm = |c: &str| table_rgb(c).unwrap_or_else(|| c.to_ascii_lowercase()); + let picked: Vec = picked.iter().map(|c| norm(c)).collect(); let list = |d: &Dialog, key: &str| -> Vec { d.fields .get("colorTable") @@ -1392,12 +1405,12 @@ pub(super) fn delete_colors(d: &mut Dialog, palette: &[String]) -> Result<(), St .into_iter() .flatten() .filter_map(Value::as_str) - .map(str::to_ascii_lowercase) + .map(norm) .collect() }; let mut custom = list(d, "customPalette"); if custom.is_empty() { - custom = palette.iter().map(|c| c.to_ascii_lowercase()).collect(); + custom = palette.iter().map(|c| norm(c)).collect(); } let mut deleted = list(d, "deleted"); for c in &picked { @@ -1491,16 +1504,25 @@ fn shifts(d: &Dialog) -> Map { d.fields.get("colorTable").and_then(|t| t.get("shifted")).and_then(Value::as_object).cloned().unwrap_or_default() } -/// Whether `a` and `b` name one color, however each is written; text that is not a color matches -/// the same text in any case. +/// Whether `a` and `b` name one color, however each is written, as the engine reads the table's +/// colors; other text, a spelling with alpha included (four or eight hex digits), matches only the +/// same text in any case. fn same_color(a: &str, b: &str) -> bool { - let rgb = |h: &str| vectorcraft_color::Color::from_hex(h).map(|c| c.to_hex()); - match (rgb(a), rgb(b)) { + match (table_rgb(a), table_rgb(b)) { (Some(a), Some(b)) => a == b, _ => a.eq_ignore_ascii_case(b), } } +/// The color `h` names as `#rrggbb`, read as the engine reads the table's colors: `None` for text +/// that is not a color and for a spelling with alpha (four or eight hex digits). +fn table_rgb(h: &str) -> Option { + let t = h.trim(); + let digits = t.strip_prefix('#').unwrap_or(t); + let alpha = matches!(digits.len(), 4 | 8) && digits.chars().all(|c| c.is_ascii_hexdigit()); + if alpha { None } else { vectorcraft_color::Color::from_hex(t).map(|c| c.to_hex()) } +} + /// Take the shift by hand of the source color `source` away: every key that names that color. pub(super) fn unshift(d: &mut Dialog, source: &str) { let mut map = shifts(d); diff --git a/crates/ui-egui/src/dialogs/tests_save_for_web.rs b/crates/ui-egui/src/dialogs/tests_save_for_web.rs index b93c36def8..1c8c6f17be 100644 --- a/crates/ui-egui/src/dialogs/tests_save_for_web.rs +++ b/crates/ui-egui/src/dialogs/tests_save_for_web.rs @@ -798,6 +798,51 @@ fn colour_table_selection_and_delete_color() { assert_eq!((&d.fields["colorTable"]["deleted"], &d.fields["colorTable"]["customPalette"]), (&json!([]), &json!([]))); } +/// A selection written another way (`#00F`) is deleted as the table writes it, so deleting the +/// table's only color is refused with nothing changed; a spelling with alpha names no table color. +#[test] +fn delete_color_matches_a_selection_written_another_way() { + let mut d = Dialog::new(save_for_web::KIND, json!({})); + let shown: Vec = ["#0000ff"].map(String::from).to_vec(); + d.fields.insert("__colors".into(), json!(["#00F", "#0000FF"])); + assert_eq!(save_for_web::selected_in(&d, &shown), ["#0000ff"]); + let before = d.fields.clone(); + assert_eq!(save_for_web::delete_colors(&mut d, &shown), Err(vectorcraft_engine::cmd::webexport::KEEP_ONE.to_string())); + assert_eq!(d.fields, before); + d.fields.insert("__colors".into(), json!(["#0000ff80"])); + assert!(save_for_web::selected_in(&d, &shown).is_empty()); +} + +/// A Ctrl-click on a selected color takes out every selection entry that names it, however each is +/// written (`#00F`, `#0000ff`). +#[test] +fn command_click_deselects_every_spelling_of_a_color() { + let order: Vec = ["#0000ff", "#ff0000"].map(String::from).to_vec(); + let mut d = Dialog::new(save_for_web::KIND, json!({})); + d.fields.insert("__colors".into(), json!(["#ff0000", "#00F", "#0000ff"])); + save_for_web::pick(&mut d, &order, "#0000ff", false, true); + assert_eq!(save_for_web::selection(&d), ["#ff0000"]); + assert_eq!(d.fields["__color"], json!("#ff0000")); +} + +/// Delete Color compares the table's lists as colors: with blue mapped to transparent as `#00f`, +/// deleting red (selected as `#f00`), the only other color, is refused with nothing changed, and a +/// deleted color written another way in `locked` (`blue`, ` #0000FF `) is taken out of the list. +#[test] +fn delete_color_compares_lists_written_another_way() { + let shown: Vec = ["#0000ff", "#ff0000"].map(String::from).to_vec(); + let mut d = Dialog::new(save_for_web::KIND, json!({"colorTable": {"transparent": ["#00f"]}})); + d.fields.insert("__color".into(), json!("#f00")); + let before = d.fields.clone(); + assert_eq!(save_for_web::delete_colors(&mut d, &shown), Err(vectorcraft_engine::cmd::webexport::KEEP_ONE.to_string())); + assert_eq!(d.fields, before); + let mut d = Dialog::new(save_for_web::KIND, json!({"colorTable": {"locked": ["blue", " #0000FF ", "#ff0000"]}})); + d.fields.insert("__color".into(), json!("#00F")); + save_for_web::delete_colors(&mut d, &shown).unwrap(); + assert_eq!(d.fields["colorTable"]["locked"], json!(["#ff0000"])); + assert_eq!(d.fields["colorTable"]["deleted"], json!(["#0000ff"])); +} + /// Delete Color takes only selected colors the table shows: a selection the table no longer holds /// (after a change of reduction or color count, or set through `ui.dialog.set`) deletes nothing, /// fixes no palette and is cleared, and a selection partly in the table deletes only what it shows. @@ -1023,6 +1068,37 @@ fn table_buttons_skip_a_selected_color_the_table_does_not_show() { assert!(has(&app, "locked", "#0000ff"), "{}", table(&app)); } +/// A list entry written another way (`#00F`) names the selected color: the buttons show Unlock, +/// Unshift and Restore, and a click takes the color out of the list. +#[test] +fn table_buttons_match_a_color_written_another_way() { + let dir = vectorcraft_testkit::temp_dir("sfw-short-hex"); + let (mut app, _) = app(&dir, false); + app.run("shape.rectangle", json!({"x": 40, "y": 0, "width": 20, "height": 40})).unwrap(); + app.run("paint.setFill", json!({"color": "#0000ff"})).unwrap(); + app.run("file.saveForWeb", json!({})).unwrap(); + for (k, v) in [("format", json!("gif")), ("antiAlias", json!("none")), ("dither", json!("none"))] { + set(&mut app, k, v); + } + let table = |app: &VectorcraftApp| app.ui.dialog.as_ref().and_then(|d| d.fields.get("colorTable").cloned()).unwrap_or_default(); + for (list, label) in [("locked", "Unlock"), ("webShift", "Unshift"), ("transparent", "Restore")] { + set(&mut app, "colorTable", json!({ list: ["#00F"] })); + set(&mut app, "__color", json!("#0000ff")); + click_text(&mut app, label); + assert_eq!(table(&app)[list], json!([]), "{list}"); + } + // Selected as `#00F`, a click adds the color as the table writes it. + set(&mut app, "colorTable", json!({})); + set(&mut app, "__color", json!("#00F")); + click_text(&mut app, "Lock"); + assert_eq!(table(&app)["locked"], json!(["#0000ff"])); + // A spelling with alpha names no table color: the buttons stay off and nothing is added. + set(&mut app, "colorTable", json!({})); + set(&mut app, "__color", json!("#0000ff80")); + click_text(&mut app, "Lock"); + assert_eq!(table(&app).get("locked"), None, "{}", table(&app)); +} + /// Click the dialog's text `label` with the pointer (frames a quarter second apart). fn click_text(app: &mut VectorcraftApp, label: &str) { let ctx = egui::Context::default(); diff --git a/docs/mcp.md b/docs/mcp.md index af2a1514ff..32ae51c7cd 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -10568,7 +10568,9 @@ included), and two keys that name one color are errors. Presets and `webExport.s opaque swatch opens the Color Picker on the color shown (on the source color for a color already shifted; an agent sets `__editColor: "#source"`). Its OK shifts the color (picking the source color takes the shift away), and Cancel leaves the table as it was. An OK that would shift a 257th color changes nothing, and the status bar shows the -limit. A key written another way (`#F00`) still names its color, so a new shift or Unshift replaces it. Done or Save +limit. A key written another way (`#F00`) still names its color, so a new shift or Unshift replaces it. A selected +color (`__color`, `__colors`) or list entry written another way also names its table color: Lock, Transparent, Web +Shift and Delete Color act on it and write it as the table does, and a `#rrggbbaa` spelling names no table color. Done or Save right after the OK keeps the shift. A shifted swatch shows the source color at its upper left and the new color at its lower right, with the lock mark, and Lock stays on until the color is unshifted. Web Shift replaces a shift by hand, and Unshift All Colors in the table's menu clears `shifted` and `webShift`. Only Web Colors in the picker starts off. From 782715d46771fa709faf13f7ec917ba7e8a4dd4f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 09:52:58 -0800 Subject: [PATCH 10/26] Undo: a drag after a command replays on its own objects When a command run during a tool drag deletes, hides or locks an object that the drag's preview names in its ids, the preview applied again leaves that object out, so the drag still edits the others. A preview left naming no object records no step. When the command changes the selection, the journal also records the drag's own selection after the command (select.set, with its anchors, segments, guides and key, or its slices, target, symbol part or Objects on Path member), so replaying the journal moves the objects the drag moved. A targeted object keeps its guides and key, and a path with every anchor selected keeps them selected as anchors. The current layer and the highlighted Layers panel rows are left as the drag left them. --- crates/engine/src/session/edit.rs | 137 +++++++++- .../engine/src/tests/interaction_commands.rs | 258 ++++++++++++++++++ 2 files changed, 394 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/session/edit.rs b/crates/engine/src/session/edit.rs index 5930c8d9c0..cbf9bf4931 100644 --- a/crates/engine/src/session/edit.rs +++ b/crates/engine/src/session/edit.rs @@ -383,10 +383,19 @@ impl Session { } return; } - it.doc = st.doc.clone(); + let began = std::mem::replace(&mut it.doc, st.doc.clone()); // The drag acts on the objects it began with: a selection the command made (a paste, a // duplicate, Select All) does not change what the drag moves. it.selection = Arc::new(drag_selection(&it.selection, &st.doc)); + // The journal holds the selection the command left. The drag's own selection is journaled + // after it, so the drag and the commands after it replay on the objects they act on. + let reselect = (active && st.selection != *it.selection) + .then(|| selection_steps(&it.selection, &st.selection, &st.doc, st.active_layer, &st.highlighted_rows())); + // The objects the drag's preview names leave out those the command removed, hid or locked. + // A preview left naming none has nothing to apply, and the drag records no step. + if it.preview.as_mut().is_some_and(|(_, p)| !drag_targets(p, &began, &st.doc)) { + it.preview = None; + } it.copies = None; it.move_box = std::sync::OnceLock::new(); // With Real-time Drawing off the preview waits for the commit, as it did before the command. @@ -398,6 +407,13 @@ impl Session { st.revision += 1; } st.interaction = Some(it); + 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.clear_deferred_overlay_cache(); if let Some((cmd, p)) = again { match self.preview(&cmd, &p) { @@ -686,3 +702,122 @@ fn drag_selection(began: &Selection, doc: &Document) -> Selection { selection.remove_all(held); selection } + +/// Take out of the `ids` of a drag's preview `params` the objects that a command run during the +/// drag removed from `doc`, or hid or locked there while they were editable in `began` → false +/// when the preview named objects and none of them is left. +fn drag_targets(params: &mut Value, began: &Document, doc: &Document) -> bool { + let Some(ids) = params.get_mut("ids").and_then(Value::as_array_mut) else { return true }; + if ids.is_empty() { + return true; + } + let (was, now) = (began.editable(), doc.editable()); + ids.retain(|v| v.as_u64().map(vectorcraft_doc::NodeId).is_none_or(|id| doc.node(id).is_some() && (now(id) || !was(id)))); + !ids.is_empty() +} + +/// The journal entries that select `selection` again in `doc` after `made`, the selection a +/// command left with `layer` current and `rows` highlighted in the Layers panel ([`object_steps`]). +/// When selecting the objects would make another layer current, `layer.setCurrent` makes `layer` +/// current again, as the drag leaves it, and `layer.highlight` gives back the highlighted rows. +fn selection_steps( + selection: &Selection, + made: &Selection, + doc: &Document, + layer: Option, + rows: &[vectorcraft_doc::NodeId], +) -> Vec<(String, Value)> { + let mut steps = object_steps(selection, doc); + // `layer.target` on a layer makes it current; any other change to the selected objects makes + // the layer of the last selected object current. + let targeted = steps.first().is_some_and(|(id, _)| id == "layer.target"); + let selects = match selection.target.filter(|t| targeted && doc.node(*t).is_some_and(|n| n.is_layer())) { + Some(t) => Some(t), + None if selection.objects != made.objects => { + selection.objects.last().and_then(|id| doc.layer_containing(*id)).filter(|l| doc.is_editable(*l)) + } + None => None, + }; + if let Some(layer) = layer.filter(|l| selects.is_some_and(|s| s != *l)) { + steps.push(("layer.setCurrent".into(), serde_json::json!({ "id": layer.0 }))); + // `layer.setCurrent` highlights the layer's row. `layer.highlight` sets the rows the command + // left instead; it keeps `layer` current while the last of them is on `layer`, or none is left. + if rows != [layer] && rows.last().is_none_or(|r| doc.layer_containing(*r) == Some(layer)) { + let ids: Vec = rows.iter().map(|r| r.0).collect(); + steps.push(("layer.highlight".into(), serde_json::json!({ "ids": ids, "mode": "set" }))); + } + } + steps +} + +/// The journal entries that select `selection` in `doc`: the selections made on their own (its +/// slices with `object.slice.select`, its target with `layer.target`, its symbol part with +/// `symbol.instance.selectPart`, its Objects on Path member with +/// `object.objectsOnPath.selectMember`), or its objects in their order (`select.set`), the anchors +/// left out on paths that are not selected whole (`select.anchorsMany`), the anchors of paths with +/// every anchor selected (`select.anchors`) and its segments (`select.segments`); after its objects +/// or its target, its ruler guides (`guide.select`) and its key object, key guide or key anchor +/// (`select.key`). +fn object_steps(selection: &Selection, doc: &Document) -> Vec<(String, Value)> { + use serde_json::json; + if !selection.slices.is_empty() { + let slices: Vec = selection.slices.iter().map(|id| id.0).collect(); + return vec![("object.slice.select".into(), json!({ "slices": slices }))]; + } + // A target is selected again only while targeting it selects the same objects: when a command + // added art to a targeted layer, `select.set` selects the drag's objects. + let targets = |t: vectorcraft_doc::NodeId| match doc.node(t) { + Some(n) if n.is_layer() => n.layer_art(true) == selection.objects, + _ => selection.objects == [t], + }; + let json_refs = |refs: &mut dyn Iterator| Value::Array(refs.map(|&(a, b)| json!([a, b])).collect()); + // A targeted object keeps the ruler guides and the key selected beside it. + let mut steps = if let Some(t) = selection.target.filter(|&t| targets(t)) { + vec![("layer.target".to_string(), json!({ "id": t.0 }))] + } else if let Some(part) = &selection.symbol_part { + return vec![("symbol.instance.selectPart".into(), json!({ "id": part.instance.0, "path": part.path }))]; + } else if let Some(member) = selection.on_path_member { + return vec![("object.objectsOnPath.selectMember".into(), json!({ "member": member.0 }))]; + } else { + let ids: Vec = selection.objects.iter().map(|id| id.0).collect(); + let mut steps = vec![("select.set".to_string(), json!({ "ids": ids }))]; + // `select.set` selects each path whole: subtracting the anchors that are not selected leaves + // the ones that are, and keeps the order of the objects. A path with every anchor selected + // as anchors gets them back with `select.anchors`, which keeps them all as anchors. + let mut every = Vec::new(); + let partial: Vec = selection + .objects + .iter() + .filter_map(|id| { + let refs = selection.anchors.get(id)?; + let path = doc.node(*id)?.path_data()?; + let out: Vec<(usize, usize)> = path.anchors().map(|(s, i, _)| (s, i)).filter(|r| !refs.contains(r)).collect(); + if out.is_empty() { + every.push(("select.anchors".to_string(), json!({ "id": id.0, "anchors": json_refs(&mut refs.iter()), "mode": "add" }))); + return None; + } + Some(json!({ "id": id.0, "anchors": json_refs(&mut out.iter()) })) + }) + .collect(); + if !partial.is_empty() { + steps.push(("select.anchorsMany".into(), json!({ "items": partial, "mode": "subtract" }))); + } + steps.extend(every); + for (id, refs) in &selection.segments { + steps.push(("select.segments".into(), json!({ "id": id.0, "segments": json_refs(&mut refs.iter()), "mode": "add" }))); + } + steps + }; + if !selection.guides.is_empty() { + let indexes = cmd::guide_indexes(doc, &selection.guides); + steps.push(("guide.select".into(), json!({ "indexes": indexes, "toggle": true }))); + } + if let Some((id, (s, i))) = selection.key_anchor { + steps.push(("select.key".into(), json!({ "id": id.0, "anchor": [s, i] }))); + } else if let Some(g) = selection.key_guide.and_then(|g| cmd::guide_indexes(doc, &[g]).first().copied()) { + steps.push(("select.key".into(), json!({ "guide": g }))); + } else if let Some(key) = selection.key { + steps.push(("select.key".into(), json!({ "id": key.0 }))); + } + steps +} diff --git a/crates/engine/src/tests/interaction_commands.rs b/crates/engine/src/tests/interaction_commands.rs index e18b0db56d..71e23f6382 100644 --- a/crates/engine/src/tests/interaction_commands.rs +++ b/crates/engine/src/tests/interaction_commands.rs @@ -400,6 +400,264 @@ fn a_selection_made_during_a_move_drag_leaves_the_paints_of_the_drag_object() { } } +/// Replay the journal of `s` from `start` on `replayed`. +fn replay_from(s: &Session, start: usize, replayed: &mut Session) { + for (id, p) in s.journal.iter().skip(start) { + replayed.replay(id, p).unwrap(); + } +} + +/// The journal of a move drag with a selection command run during it replays as the drag went: +/// the drag moves its own object, not the one the command selected. +#[test] +fn a_move_drag_after_a_selection_command_replays_on_its_own_object() { + for real_time in [true, false] { + let at = format!("real time {real_time}"); + let (mut s, target, other) = two_squares(real_time); + s.select_tool("selection", view()).unwrap(); + let start = s.journal.len(); + drag_with(&mut s, &[(120.0, 120.0), (140.0, 130.0), (170.0, 150.0)], |s| { + s.execute("select.set", &json!({"ids": [other.0]})).unwrap(); + }); + let bounds = |s: &Session| { + let d = &s.doc().unwrap().doc; + (d.bounds_of(&[target], false), d.bounds_of(&[other], false)) + }; + assert_eq!(bounds(&s), (Some(Rect::new(150.0, 130.0, 190.0, 170.0)), Some(Rect::new(10.0, 10.0, 30.0, 30.0))), "{at}"); + let (mut replayed, _, _) = two_squares(real_time); + replay_from(&s, start, &mut replayed); + assert_eq!(bounds(&replayed), bounds(&s), "{at}: {:?}", journaled(&s, start)); + assert_eq!(replayed.doc().unwrap().selection.objects, s.doc().unwrap().selection.objects, "{at}"); + assert_eq!(replayed.doc().unwrap().active_layer, s.doc().unwrap().active_layer, "{at}"); + } +} + +/// A square on a second layer selected with a ruler guide, and a square on the first layer → +/// the session (with Real-time Drawing `real_time`) and the square on the first layer. +fn square_and_guide(real_time: bool) -> (Session, NodeId) { + let mut s = Session::new(); + s.prefs.real_time_drawing = real_time; + s.execute("file.new", &json!({"width": 400, "height": 400})).unwrap(); + s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); + let other = s.doc().unwrap().selection.objects[0]; + s.execute("layer.new", &json!({})).unwrap(); + s.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 40, "height": 40})).unwrap(); + let target = s.doc().unwrap().selection.objects[0]; + s.execute("guide.add", &json!({"vertical": true, "pos": 300})).unwrap(); + s.execute("select.set", &json!({"ids": [target.0]})).unwrap(); + s.execute("guide.select", &json!({"indexes": [0], "toggle": true})).unwrap(); + (s, other) +} + +/// The journal of a move drag of a square and a ruler guide, with a command during it that +/// selects an object on another layer, replays with the drag's selection, guide included, with +/// the layer the command made current and with the Layers panel rows the command left highlighted. +#[test] +fn a_move_drag_of_a_guide_after_a_selection_command_replays_its_selection_and_layer() { + for real_time in [true, false] { + let at = format!("real time {real_time}"); + let (mut s, other) = square_and_guide(real_time); + s.select_tool("selection", view()).unwrap(); + let start = s.journal.len(); + drag_with(&mut s, &[(120.0, 120.0), (140.0, 130.0), (170.0, 150.0)], |s| { + s.execute("select.set", &json!({"ids": [other.0]})).unwrap(); + }); + let (mut replayed, _) = square_and_guide(real_time); + replay_from(&s, start, &mut replayed); + let state = |s: &mut Session| { + let d = s.doc().unwrap(); + let state = ( + d.selection.objects.clone(), + d.selection.guides.clone(), + d.active_layer, + d.highlighted_rows(), + d.doc.bounds_of(&d.selection.objects, false), + ); + (state, s.execute("guide.list", &json!({})).unwrap()) + }; + assert_eq!(state(&mut replayed), state(&mut s), "{at}: {:?}", journaled(&s, start)); + } +} + +/// The journal of a move drag of a targeted square, with a command during it that selects another +/// square, replays with the square targeted, as the drag leaves it. +#[test] +fn a_move_drag_of_a_targeted_object_after_a_selection_command_replays_its_target() { + for real_time in [true, false] { + let at = format!("real time {real_time}"); + let setup = || { + let (mut s, target, other) = two_squares(real_time); + s.execute("layer.target", &json!({"id": target.0})).unwrap(); + s.select_tool("selection", view()).unwrap(); + (s, other) + }; + let (mut s, other) = setup(); + let start = s.journal.len(); + drag_with(&mut s, &[(120.0, 120.0), (140.0, 130.0), (170.0, 150.0)], |s| { + s.execute("select.set", &json!({"ids": [other.0]})).unwrap(); + }); + let (mut replayed, _) = setup(); + replay_from(&s, start, &mut replayed); + let state = |s: &Session| { + let d = s.doc().unwrap(); + (d.selection.objects.clone(), d.selection.target, d.doc.bounds_of(&d.selection.objects, false)) + }; + assert_eq!(state(&replayed), state(&s), "{at}: {:?}", journaled(&s, start)); + } +} + +/// The journal of a move drag of a targeted square and a ruler guide, with a command during it +/// that selects another square, replays with the square targeted and the guide selected. +#[test] +fn a_move_drag_of_a_targeted_object_and_a_guide_after_a_selection_command_replays_both() { + for real_time in [true, false] { + let at = format!("real time {real_time}"); + let setup = || { + let (mut s, target, other) = two_squares(real_time); + s.execute("guide.add", &json!({"vertical": true, "pos": 300})).unwrap(); + s.execute("layer.target", &json!({"id": target.0})).unwrap(); + s.execute("guide.select", &json!({"indexes": [0], "toggle": true})).unwrap(); + s.select_tool("selection", view()).unwrap(); + (s, target, other) + }; + let (mut s, target, other) = setup(); + let start = s.journal.len(); + drag_with(&mut s, &[(120.0, 120.0), (140.0, 130.0), (170.0, 150.0)], |s| { + s.execute("select.set", &json!({"ids": [other.0]})).unwrap(); + }); + let state = |s: &mut Session| { + let d = s.doc().unwrap(); + let state = (d.selection.objects.clone(), d.selection.target, d.selection.guides.clone(), d.doc.bounds_of(&d.selection.objects, false)); + (state, s.execute("guide.list", &json!({})).unwrap()) + }; + let live = state(&mut s); + assert_eq!((live.0.1, live.0.2.len()), (Some(target), 1), "{at}: the drag leaves the square targeted and the guide selected"); + let (mut replayed, _, _) = setup(); + replay_from(&s, start, &mut replayed); + assert_eq!(state(&mut replayed), live, "{at}: {:?}", journaled(&s, start)); + } +} + +/// The journal of a move drag of a path with every anchor selected as anchor points, with a +/// command during it that selects another square, replays with those anchors selected. +#[test] +fn a_move_drag_of_every_anchor_of_a_path_after_a_selection_command_replays_its_anchors() { + for real_time in [true, false] { + let at = format!("real time {real_time}"); + let setup = || { + let (mut s, target, other) = two_squares(real_time); + s.execute("select.set", &json!({"ids": [target.0]})).unwrap(); + s.execute("select.anchors", &json!({"id": target.0, "anchors": [[0, 0]], "mode": "add"})).unwrap(); + s.select_tool("selection", view()).unwrap(); + (s, target, other) + }; + let (mut s, target, other) = setup(); + let every = s.doc().unwrap().selection.anchors.get(&target).cloned(); + assert!(every.as_ref().is_some_and(|a| a.len() > 1), "{at}: {every:?}"); + let start = s.journal.len(); + drag_with(&mut s, &[(120.0, 120.0), (140.0, 130.0), (170.0, 150.0)], |s| { + s.execute("select.set", &json!({"ids": [other.0]})).unwrap(); + }); + let state = |s: &Session| { + let d = s.doc().unwrap(); + (d.selection.objects.clone(), d.selection.anchors.clone(), d.doc.bounds_of(&d.selection.objects, false)) + }; + assert_eq!(state(&s).1.get(&target), every.as_ref(), "{at}: the drag leaves every anchor selected as anchors"); + let (mut replayed, _, _) = setup(); + replay_from(&s, start, &mut replayed); + assert_eq!(state(&replayed), state(&s), "{at}: {:?}", journaled(&s, start)); + } +} + +/// The journal of a move drag of a targeted layer's art, with a duplicate made on that layer +/// during it, replays with the drag moving its own objects, not the duplicates. +#[test] +fn a_move_drag_of_a_targeted_layer_after_a_duplicate_replays_its_objects() { + for real_time in [true, false] { + let at = format!("real time {real_time}"); + let setup = || { + let (mut s, _, _) = two_squares(real_time); + let layer = s.doc().unwrap().doc.layers[0].id; + s.execute("layer.target", &json!({"id": layer.0})).unwrap(); + s.select_tool("selection", view()).unwrap(); + s + }; + let mut s = setup(); + let start = s.journal.len(); + drag_with(&mut s, &[(120.0, 120.0), (140.0, 130.0), (170.0, 150.0)], |s| { + s.execute("edit.duplicate", &json!({})).unwrap(); + }); + let mut replayed = setup(); + replay_from(&s, start, &mut replayed); + let state = |s: &Session| { + let d = s.doc().unwrap(); + (d.selection.objects.clone(), d.doc.bounds_of(&d.selection.objects, false), objects(s)) + }; + assert_eq!(state(&replayed), state(&s), "{at}: {:?}", journaled(&s, start)); + } +} + +/// A selected user slice and a square → the session (with Real-time Drawing `real_time`), the +/// slice and the square. +fn slice_and_square(real_time: bool) -> (Session, NodeId, NodeId) { + let mut s = Session::new(); + s.prefs.real_time_drawing = real_time; + s.execute("file.new", &json!({"width": 400, "height": 400})).unwrap(); + s.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); + let other = s.doc().unwrap().selection.objects[0]; + let slice = s.execute("object.slice.create", &json!({"x": 200, "y": 200, "width": 50, "height": 50})).unwrap()["id"].as_u64().unwrap(); + s.execute("object.slice.select", &json!({"slices": [slice]})).unwrap(); + (s, NodeId(slice), other) +} + +/// The journal of a Slice Selection drag, with a command during it that selects an object, +/// replays with the slice selected, as the drag leaves it. +#[test] +fn a_slice_drag_after_a_selection_command_replays_its_slice_selection() { + for real_time in [true, false] { + let at = format!("real time {real_time}"); + let (mut s, slice, other) = slice_and_square(real_time); + s.select_tool("sliceSelection", view()).unwrap(); + let start = s.journal.len(); + drag_with(&mut s, &[(220.0, 220.0), (230.0, 230.0), (240.0, 240.0)], |s| { + s.execute("select.set", &json!({"ids": [other.0]})).unwrap(); + }); + assert_eq!(s.doc().unwrap().selection.slices, [slice], "{at}"); + let (mut replayed, _, _) = slice_and_square(real_time); + replay_from(&s, start, &mut replayed); + let state = |s: &Session| { + let sel = &s.doc().unwrap().selection; + (sel.objects.clone(), sel.slices.clone()) + }; + assert_eq!(state(&replayed), state(&s), "{at}: {:?}", journaled(&s, start)); + } +} + +/// A Warp stroke over two selected squares, with a command that deletes one of them during the +/// stroke: the release still warps the other square, and the stroke's journal entry names it. +#[test] +fn a_warp_stroke_over_an_object_a_command_deleted_still_warps_the_others() { + for real_time in [true, false] { + let at = format!("real time {real_time}"); + let (mut s, target, other) = two_squares(real_time); + s.execute("select.all", &json!({})).unwrap(); + s.select_tool("warp", view()).unwrap(); + let before = s.doc().unwrap().doc.node(target).cloned(); + let steps = s.doc().unwrap().history.undo.len(); + pointer(&mut s, PointerKind::Down, 120.0, 120.0); + pointer(&mut s, PointerKind::Drag, 135.0, 125.0); + let r = s.execute("edit.clear", &json!({"ids": [other.0]})).unwrap(); + assert!(r.get("warning").is_none(), "{at}: {r}"); + pointer(&mut s, PointerKind::Up, 135.0, 125.0); + assert!(!s.in_interaction(), "{at}"); + assert!(s.doc().unwrap().doc.node(other).is_none(), "{at}: the deletion stays"); + assert_ne!(s.doc().unwrap().doc.node(target).cloned(), before, "{at}: the release warps the other square"); + assert_eq!(s.doc().unwrap().history.undo.len(), steps + 2, "{at}: the deletion and the stroke are a step each"); + let (id, p) = s.journal.last().unwrap(); + assert_eq!((id.as_str(), &p["ids"]), ("object.liquify", &json!([target.0])), "{at}"); + } +} + /// The Scale and Rotate tools and the Pen adding to a path, with a command that deletes the /// object they act on during the drag: the drag ends without an edit of its own and the deletion /// stays. From 232b3de397d166060f1e82e314dbb1af8c12d2be Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 10:17:18 -0800 Subject: [PATCH 11/26] Tests: drag command test uses craft::automation's request and reply types After the craft UI framework move, `control` no longer exports `ControlRequest` or `Outcome`; `control::handle` takes a `craft::automation::ControlRequest` and returns a `Reply`. --- crates/ui-egui/src/tests/drag_commands.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/tests/drag_commands.rs b/crates/ui-egui/src/tests/drag_commands.rs index 8879c3e25c..1c087bb5ec 100644 --- a/crates/ui-egui/src/tests/drag_commands.rs +++ b/crates/ui-egui/src/tests/drag_commands.rs @@ -8,8 +8,8 @@ use crate::VectorcraftApp; /// Send a control request → its reply. fn control(app: &mut VectorcraftApp, ctx: &egui::Context, method: &str, params: Value) -> Value { - let (request, _) = crate::control::ControlRequest::new(method, params); - let crate::control::Outcome::Done(reply) = crate::control::handle(app, ctx, &request) else { panic!("{method}: not done") }; + let (request, _) = craft::automation::ControlRequest::new(method, params); + let craft::automation::Reply::Done(reply) = crate::control::handle(app, ctx, &request) else { panic!("{method}: not done") }; reply } From 76c4689e02334fb4ff0e8af844862dbba4727bf8 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 11:33:29 -0800 Subject: [PATCH 12/26] Save for Web: shifts the engine drops do not count toward the 256 limit A key shifted to itself or a deleted color no longer counts toward the 256 shifts, and a new shift writes `shifted` without those entries. A map the engine refuses (a key or value that is not a color, two keys naming one color) is kept whole, so the engine still reports it. Docs: docs/mcp.md. --- crates/ui-egui/src/dialogs/save_for_web.rs | 31 +++++++++++++++++-- .../ui-egui/src/dialogs/tests_save_for_web.rs | 20 ++++++++++++ docs/mcp.md | 2 +- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/dialogs/save_for_web.rs b/crates/ui-egui/src/dialogs/save_for_web.rs index 4ba055b558..6256881398 100644 --- a/crates/ui-egui/src/dialogs/save_for_web.rs +++ b/crates/ui-egui/src/dialogs/save_for_web.rs @@ -1479,17 +1479,44 @@ fn take_shift(d: &mut Dialog) -> Result<(), String> { /// Shift the source color `source` to `to` (`colorTable.shifted`), wherever it is in the image; it /// is no longer web-shifted. Picking the source color itself takes the shift away. The color /// becomes the selection. Nothing changes when either is not a color, and a new source when 256 -/// colors are already shifted is an error that changes nothing. +/// colors are already shifted is an error that changes nothing. Entries the engine drops (a color +/// shifted to itself, a deleted color) do not count, and a new shift writes the map without them. pub(super) fn shift_color(d: &mut Dialog, source: &str, to: &str) -> Result<(), String> { let hex = |h: &str| vectorcraft_color::Color::from_hex(h).map(|c| c.to_hex()); let (Some(source), Some(to)) = (hex(source), hex(to)) else { return Ok(()) }; + let deleted: Vec = d + .fields + .get("colorTable") + .and_then(|t| t.get("deleted")) + .and_then(Value::as_array) + .into_iter() + .flatten() + .filter_map(Value::as_str) + .map(String::from) + .collect(); let map = shifts(d); - if to != source && map.len() >= webexport::MAX_TABLE && !map.keys().any(|k| same_color(k, &source)) { + // Entries are dropped only from a map the engine accepts (every key and value a color, no two + // keys naming one color); any other map is kept whole for the engine to refuse. + let mut keys: Vec = Vec::new(); + let valid = map.iter().all(|(k, v)| match (table_rgb(k), v.as_str().and_then(table_rgb)) { + (Some(k), Some(_)) if !keys.contains(&k) => { + keys.push(k); + true + } + _ => false, + }); + let live = |k: &str, v: &Value| { + let (true, Some(key), Some(to)) = (valid, table_rgb(k), v.as_str().and_then(table_rgb)) else { return true }; + to != key && !deleted.iter().any(|x| table_rgb(x).is_some_and(|x| x == key)) + }; + let count = map.iter().filter(|(k, v)| live(k, v)).count(); + if to != source && count >= webexport::MAX_TABLE && !map.iter().any(|(k, v)| live(k, v) && same_color(k, &source)) { return Err(webexport::too_many("shifted")); } unshift(d, &source); if to != source { let mut map = shifts(d); + map.retain(|k, v| live(k, v)); map.insert(source.clone(), json!(to)); set_table(d, "shifted", Value::Object(map)); } diff --git a/crates/ui-egui/src/dialogs/tests_save_for_web.rs b/crates/ui-egui/src/dialogs/tests_save_for_web.rs index 1c8c6f17be..c8bbd9526b 100644 --- a/crates/ui-egui/src/dialogs/tests_save_for_web.rs +++ b/crates/ui-egui/src/dialogs/tests_save_for_web.rs @@ -921,6 +921,26 @@ fn colour_table_shift_holds_at_most_256_colors() { assert_eq!(d.fields["colorTable"]["shifted"]["#123456"], "#000000"); } +/// Entries the engine drops (a color shifted to itself, a deleted color) do not count toward the +/// 256 shifts, and a new shift writes the map without them. +#[test] +fn colour_table_shift_skips_entries_the_engine_drops() { + let mut full: serde_json::Map = (0..255).map(|i| (format!("#{i:06x}"), json!(format!("#{i:06x}")))).collect(); + full.insert("#abcdef".into(), json!("#000000")); + let mut d = Dialog::new(save_for_web::KIND, json!({"colorTable": {"shifted": full, "deleted": ["#ABCDEF"]}})); + save_for_web::shift_color(&mut d, "#123456", "#000000").unwrap(); + assert_eq!(d.fields["colorTable"]["shifted"], json!({"#123456": "#000000"})); + // A map the engine refuses (a value that is not a color, two keys naming one color) is kept + // whole for the engine to refuse. + for shifted in [json!({"nope": "NOPE"}), json!({"#abcdef": "nope"}), json!({"#f00": "#f00", "#FF0000": "#00ff00"})] { + let mut d = Dialog::new(save_for_web::KIND, json!({"colorTable": {"shifted": shifted.clone(), "deleted": ["#abcdef"]}})); + save_for_web::shift_color(&mut d, "#123456", "#000000").unwrap(); + let mut want = shifted.as_object().cloned().unwrap_or_default(); + want.insert("#123456".into(), json!("#000000")); + assert_eq!(d.fields["colorTable"]["shifted"], serde_json::Value::Object(want), "{shifted}"); + } +} + /// One frame of `app` in `ctx`, 50 ms after the last. fn tick(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec) { let time = ctx.input(|i| i.time) + 0.05; diff --git a/docs/mcp.md b/docs/mcp.md index 32ae51c7cd..641f705089 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -10568,7 +10568,7 @@ included), and two keys that name one color are errors. Presets and `webExport.s opaque swatch opens the Color Picker on the color shown (on the source color for a color already shifted; an agent sets `__editColor: "#source"`). Its OK shifts the color (picking the source color takes the shift away), and Cancel leaves the table as it was. An OK that would shift a 257th color changes nothing, and the status bar shows the -limit. A key written another way (`#F00`) still names its color, so a new shift or Unshift replaces it. A selected +limit; a key shifted to itself or a deleted color does not count, and a new shift writes `shifted` without them. A key written another way (`#F00`) still names its color, so a new shift or Unshift replaces it. A selected color (`__color`, `__colors`) or list entry written another way also names its table color: Lock, Transparent, Web Shift and Delete Color act on it and write it as the table does, and a `#rrggbbaa` spelling names no table color. Done or Save right after the OK keeps the shift. A shifted swatch shows the source color at its upper left and the new color at its lower From 7a37e282d93b056ad6062030a56cf73e19327114 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 12:50:43 -0800 Subject: [PATCH 13/26] Undo: putting back a drag's paints names every PaintDefaults field put_back_interaction compares the new-art paints field by field. It now destructures PaintDefaults without `..`, so a field added to the struct does not compile until it is handled there. --- crates/engine/src/session/edit.rs | 38 ++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/crates/engine/src/session/edit.rs b/crates/engine/src/session/edit.rs index 464c92b09e..a70850f44d 100644 --- a/crates/engine/src/session/edit.rs +++ b/crates/engine/src/session/edit.rs @@ -362,31 +362,33 @@ impl Session { } // A change the command made to the new-art paints stays when the next preview or a cancel // puts back the paints the interaction began with (the Live Paint Bucket's colors); the - // parts it left alone keep the interaction's. - let (now, start) = (&self.paint, &mut it.paint); - if now.fill != paint.fill { - start.fill.clone_from(&now.fill); + // parts it left alone keep the interaction's. The pattern lists every field, so a field + // added to `PaintDefaults` does not compile until it is handled here. + let vectorcraft_tools::PaintDefaults { fill, stroke, stroke_width, appearance, opacity, blend, style, inherited } = &self.paint; + let start = &mut it.paint; + if *fill != paint.fill { + start.fill.clone_from(fill); } - if now.stroke != paint.stroke { - start.stroke.clone_from(&now.stroke); + if *stroke != paint.stroke { + start.stroke.clone_from(stroke); } - if now.stroke_width != paint.stroke_width { - start.stroke_width = now.stroke_width; + if *stroke_width != paint.stroke_width { + start.stroke_width = *stroke_width; } - if now.appearance != paint.appearance { - start.appearance.clone_from(&now.appearance); + if *appearance != paint.appearance { + start.appearance.clone_from(appearance); } - if now.opacity != paint.opacity { - start.opacity = now.opacity; + if *opacity != paint.opacity { + start.opacity = *opacity; } - if now.blend != paint.blend { - start.blend = now.blend; + if *blend != paint.blend { + start.blend = *blend; } - if now.style != paint.style { - start.style.clone_from(&now.style); + if *style != paint.style { + start.style.clone_from(style); } - if now.inherited != paint.inherited { - start.inherited = now.inherited; + if *inherited != paint.inherited { + start.inherited = *inherited; } let active = self.active().is_some_and(|d| d.uid == uid); let Some(st) = self.docs.iter_mut().find(|d| d.uid == uid) else { return }; From ea602fcd00e0fe826fb0c980fe699b55b7601197 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 13:54:07 -0800 Subject: [PATCH 14/26] Undo: Find Objects with select during a drag is a step of its own document.find with `select: true` is journaled, so during a tool drag it now runs outside the drag like other journaled commands. It finds and selects only objects outside the drag's preview, as its replay before the drag does. --- crates/engine/src/session/execute.rs | 6 +++-- .../engine/src/tests/interaction_commands.rs | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/session/execute.rs b/crates/engine/src/session/execute.rs index 0ba94dffa2..f87d37691f 100644 --- a/crates/engine/src/session/execute.rs +++ b/crates/engine/src/session/execute.rs @@ -100,8 +100,10 @@ impl Session { } let outer = std::mem::replace(&mut self.reading, !spec.journal || JOURNALED_READS.contains(&id)); // A command from outside the tool, while the tool's drag is in progress, is a step of its - // own before the drag's ([`Session::outside_interaction`]). - let outside = spec.journal && !self.previewing && !self.in_tool_actions; + // own before the drag's ([`Session::outside_interaction`]). Find Objects with `select` is + // journaled (`Session::journal_query`), so it is one too. + let find_selects = id == "document.find" && params.get("select").and_then(Value::as_bool) == Some(true); + let outside = (spec.journal || find_selects) && !self.previewing && !self.in_tool_actions; // A preview that a top-level command applied first (a drag with Real-time Drawing off, kept // before Undo) reports its warning in the command's result. let r = if self.depth == 0 { diff --git a/crates/engine/src/tests/interaction_commands.rs b/crates/engine/src/tests/interaction_commands.rs index 71e23f6382..5234ea52ac 100644 --- a/crates/engine/src/tests/interaction_commands.rs +++ b/crates/engine/src/tests/interaction_commands.rs @@ -432,6 +432,30 @@ fn a_move_drag_after_a_selection_command_replays_on_its_own_object() { } } +/// Find Objects with `select` during a drag is a step of its own, as it is journaled: it finds and +/// selects only the objects outside the drag's preview, as its replay before the drag does. +#[test] +fn find_objects_with_select_during_a_drag_skips_the_drag_preview() { + for real_time in [true, false] { + let at = format!("real time {real_time}"); + let (mut s, other) = session(real_time); + let start = s.journal.len(); + let find = json!({"intersects": [0, 0, 400, 400], "select": true}); + pointer(&mut s, PointerKind::Down, 100.0, 100.0); + pointer(&mut s, PointerKind::Drag, 150.0, 150.0); + let r = s.execute("document.find", &find).unwrap(); + assert_eq!(r["total"], 1, "{at}: {r}"); + assert_eq!(r["matches"][0]["id"], other.0, "{at}: {r}"); + pointer(&mut s, PointerKind::Up, 200.0, 180.0); + assert_eq!(objects(&s), 2, "{at}: the release draws the rectangle"); + assert_eq!(journaled(&s, start), ["document.find", "shape.rectangle"], "{at}"); + let (mut replayed, _) = session(real_time); + replay_from(&s, start, &mut replayed); + assert_eq!(objects(&replayed), 2, "{at}"); + assert_eq!(replayed.doc().unwrap().selection.objects, s.doc().unwrap().selection.objects, "{at}"); + } +} + /// A square on a second layer selected with a ruler guide, and a square on the first layer → /// the session (with Real-time Drawing `real_time`) and the square on the first layer. fn square_and_guide(real_time: bool) -> (Session, NodeId) { From fbb3f4b59f2bcc2bdb3d51e6ea8c89fdfaf68706 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 12:10:07 -0800 Subject: [PATCH 15/26] Window menu: panel rows show their panels' shortcuts Each Window menu row ran `window.panel {panel, toggle: true}`, while the panel's shortcut entry (`panel:`) binds `window.panel {panel}`. The menu row was a separate command with no binding, so no Window row showed a chord, as production's did. The rows now name the command the shortcut runs, and the catalog holds one command per panel. `ui.menu.list` still lists each Window row with `toggle: true`, and a click on the row runs those listed params, so a click puts a showing panel away as before. A plug-in row that shows a panel the Window menu does not list (Fold Lines) keeps its params. --- crates/ui-egui/src/menus.rs | 2 +- crates/ui-egui/src/menus/entries.rs | 36 +++++++++++++++- crates/ui-egui/src/menus/tree.rs | 4 +- crates/ui-egui/src/shortcuts.rs | 7 ++-- crates/ui-egui/src/shortcuts/tests.rs | 59 +++++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 7d003be560..b7f833c9ac 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -63,7 +63,7 @@ mod ui_commands; pub use context::context_items; #[cfg(test)] use entries::flatten; -pub use entries::{InsertableItem, MenuEntry, context_entries, insertable, insertable_items, menu_entries, plays_in_app, shown_label}; +pub use entries::{InsertableItem, MenuEntry, context_entries, insertable, insertable_items, is_row_of, menu_entries, plays_in_app, shown_label}; pub(crate) use invoke::graph_dialog; pub use invoke::{click_target, invoke}; pub(crate) use labels::lists_plugin; diff --git a/crates/ui-egui/src/menus/entries.rs b/crates/ui-egui/src/menus/entries.rs index 6524edfd21..d90b4b9872 100644 --- a/crates/ui-egui/src/menus/entries.rs +++ b/crates/ui-egui/src/menus/entries.rs @@ -29,15 +29,49 @@ pub struct MenuEntry { pub shown_path: Vec, } -/// Flattened menu for `ui.menu.list`. +/// Flattened menu for `ui.menu.list`. A row that shows a panel of the Window menu, there or in another menu (Type › +/// Glyphs), lists the params a click on it runs: `window.panel` with `toggle: true`, which puts a showing panel away +/// ([`is_row_of`]). pub fn menu_entries(app: &VectorcraftApp) -> Vec { let mut out = vec![]; for (title, items) in menu_tree_named(app.session.prefs.font_names_in_english, &Listed::of(app)) { flatten(app, vec![title.to_string()], vec![crate::i18n::t(title).to_string()], &items, &mut out); } + let window_panels: Vec = out + .iter() + .filter(|e| e.path.first().is_some_and(|t| t == "Window") && e.command.as_deref() == Some(PANEL)) + .map(|e| e.params.clone()) + .collect(); + for e in &mut out { + if e.command.as_deref() == Some(PANEL) + && window_panels.contains(&e.params) + && let Some(params) = e.params.as_object_mut() + { + params.entry("toggle").or_insert(Value::Bool(true)); + } + } out } +/// The command of the rows that show a panel. +const PANEL: &str = "window.panel"; + +/// Whether `e` is the row of the menu item that runs command `id` with `params`: the same command and params, or a +/// panel row that [`menu_entries`] lists with `toggle: true` added. +pub fn is_row_of(e: &MenuEntry, id: &str, params: &Value) -> bool { + if e.command.as_deref() != Some(id) { + return false; + } + if e.params == *params { + return true; + } + let mut listed = e.params.clone(); + id == PANEL + && params.get("toggle").is_none() + && listed.as_object_mut().and_then(|o| o.remove("toggle")) == Some(Value::Bool(true)) + && listed == *params +} + /// Flattened canvas context menu for `ui.contextMenu.list` (paths are its submenus). pub fn context_entries(app: &VectorcraftApp) -> Vec { let mut out = vec![]; diff --git a/crates/ui-egui/src/menus/tree.rs b/crates/ui-egui/src/menus/tree.rs index 13b33dde44..fa5e15d238 100644 --- a/crates/ui-egui/src/menus/tree.rs +++ b/crates/ui-egui/src/menus/tree.rs @@ -45,7 +45,9 @@ impl Listed { } pub fn menu_tree_named(english_names: bool, listed: &Listed) -> Vec<(&'static str, Vec)> { - let panel = |label: &'static str, id: &'static str| cp(label, "window.panel", json!({ "panel": id, "toggle": true })); + // A Window row names the command the panel's shortcut runs, so it shows that shortcut; a click toggles the panel + // (`menu_entries` lists the row with `toggle: true`). + let panel = |label: &'static str, id: &'static str| cp(label, "window.panel", json!({ "panel": id })); vec![ ( // The application menu, shown on macOS only: the layout merges it with the items the diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs index eaa0065ba4..7ee393527f 100644 --- a/crates/ui-egui/src/shortcuts.rs +++ b/crates/ui-egui/src/shortcuts.rs @@ -276,7 +276,8 @@ fn menu_target(c: &CommandRef) -> Option<(String, serde_json::Value)> { } /// What a click on the menu bar's or the canvas menu's row `c` runs ([`crate::menus::click_target`]): a "…" row with -/// params opens its dialog on them (Clean Up…). `None` for a command that no menu fired. +/// params opens its dialog on them (Clean Up…), and a row of a Window menu panel runs the params it is listed with +/// (`toggle: true`, [`crate::menus::is_row_of`]). `None` for a command that no menu fired. fn clicked_row(app: &VectorcraftApp, source: FireSource, c: &CommandRef) -> Option<(String, serde_json::Value)> { if source != FireSource::Menu || c.params.as_object().is_none_or(serde_json::Map::is_empty) { return None; @@ -284,8 +285,8 @@ fn clicked_row(app: &VectorcraftApp, source: FireSource, c: &CommandRef) -> Opti let row = crate::menus::menu_entries(app) .into_iter() .chain(crate::menus::context_entries(app)) - .find(|e| e.command.as_deref() == Some(c.id.as_str()) && e.params == c.params)?; - Some(crate::menus::click_target(&row.label, &c.id, &c.params)) + .find(|e| crate::menus::is_row_of(e, &c.id, &c.params))?; + Some(crate::menus::click_target(&row.label, &c.id, &row.params)) } /// Params used when a shortcut invokes its command. The named panel function keys retain their diff --git a/crates/ui-egui/src/shortcuts/tests.rs b/crates/ui-egui/src/shortcuts/tests.rs index 0f302c1551..49d09ddf13 100644 --- a/crates/ui-egui/src/shortcuts/tests.rs +++ b/crates/ui-egui/src/shortcuts/tests.rs @@ -246,6 +246,65 @@ fn named_panel_default_chords_toggle_their_panels() { } } +/// Each Window menu row that shows a panel shows the chord of that panel's shortcut, as production's did, and the +/// rows of the panels with a default key show one. +#[test] +fn window_menu_panel_rows_show_their_panels_shortcuts() { + let mut app = new_app(); + let ctx = ready(&mut app); + let rows: Vec = + app.menus.bar.items().into_iter().filter(|it| it.command.id == "window.panel").map(|it| it.command.clone()).collect(); + assert!(!rows.is_empty(), "the Window menu lists panels"); + let mut shown = 0; + for row in &rows { + let panel = row.params["panel"].as_str().expect("a panel row names its panel"); + let entry = crate::keymap::command_of(&format!("panel:{panel}")); + let chord = craft::ui::runtime::commands::chord(&ctx, row); + assert_eq!(chord, craft::ui::runtime::commands::chord(&ctx, &entry), "{panel}: the row shows its shortcut's chord"); + shown += usize::from(chord.is_some()); + } + let with_keys = crate::shortcut_editor::PANEL_SHORTCUTS.iter().filter(|(panel, _)| rows.iter().any(|r| r.params["panel"] == *panel)).count(); + assert!(with_keys > 0 && shown >= with_keys, "{shown} rows show a chord, {with_keys} panels have a default key"); +} + +/// A click on a Window menu row toggles its panel: it puts a showing panel away and shows it again. +#[test] +fn a_window_menu_click_toggles_its_panel() { + use craft::ui::runtime::commands::{FirePhase, FireSource, Fired}; + let mut app = new_app(); + let ctx = ready(&mut app); + let row = app + .menus + .bar + .items() + .into_iter() + .find(|it| it.command.id == "window.panel" && it.command.params["panel"] == "layers") + .map(|it| it.command.clone()); + let row = row.expect("a Window › Layers row"); + let before = crate::panel_docking::showing(&app.ui, "layers"); + let click = |app: &mut VectorcraftApp| { + crate::shortcuts::run_fired(app, &ctx, &Fired::new(row.clone(), FireSource::Menu, FirePhase::Press, 0.0)); + key_frame(app, &ctx, vec![]); + crate::panel_docking::showing(&app.ui, "layers") + }; + let once = click(&mut app); + assert_ne!(once, before, "the first click toggles Layers"); + assert_eq!(click(&mut app), before, "the second click toggles it back"); +} + +/// `ui.menu.list` lists a Window menu panel row with the toggle a click on it runs, and a plug-in's row that shows a +/// panel the Window menu does not list (Object › Plug-ins › Packaging Tools › Fold Lines) without one. +#[test] +fn listed_window_rows_toggle_and_plugin_panel_rows_do_not() { + let app = new_app(); + let entries = crate::menus::menu_entries(&app); + let row = + |panel: &str| entries.iter().find(|e| e.command.as_deref() == Some("window.panel") && e.params["panel"] == panel).map(|e| e.params.clone()); + assert_eq!(row("layers").map(|p| p["toggle"].clone()), Some(json!(true)), "Window › Layers toggles"); + let fold = row(crate::addons::packaging::ID).expect("a Fold Lines row"); + assert!(fold.get("toggle").is_none(), "Fold Lines shows its panel: {fold}"); +} + /// A shortcut on a panel without a function key of its own runs `window.panel` with the params it has: no toggle is /// added, as production checked. #[test] From c5c54e15f25d6fe10f3160ee87eb6582f63255ec Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 18:07:00 -0800 Subject: [PATCH 16/26] Save for Web: a color shift survives Done right after the Color Picker The Color Picker's OK for a color table cell now shifts the color in the table at once, so Done or Save before the dialog draws again keeps the shift. The table marks list a color written twice in one list once. --- crates/ui-egui/src/dialogs/color_picker.rs | 9 +++- crates/ui-egui/src/dialogs/save_for_web.rs | 43 +++++++++++++++---- .../src/dialogs/save_for_web/color_table.rs | 12 +++++- .../src/dialogs/save_for_web/tests_table.rs | 29 +++++++++++++ 4 files changed, 81 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/dialogs/color_picker.rs b/crates/ui-egui/src/dialogs/color_picker.rs index 0c1f50cbb1..af1b318728 100644 --- a/crates/ui-egui/src/dialogs/color_picker.rs +++ b/crates/ui-egui/src/dialogs/color_picker.rs @@ -6,7 +6,8 @@ //! `artboard.setProps {index, color}`. //! //! A command dialog's colour row raises a `ColorRequest`; [`pump`] opens a picker over that dialog -//! and answers the row with its OK. +//! and answers the row with its OK. The OK for a Save for Web colour table cell shifts the cell's +//! colour in the table instead ([`super::save_for_web::take_palette_pick`]). //! //! Fields agents set with `ui.dialog.set`: the framework picker's (`color`, `mode`, `webColors`, //! `swatches`, `library`). `stroke`, `artboard` and `color` come from the opener. @@ -253,7 +254,11 @@ fn finish( ) { let preview = std::mem::take(&mut open.preview); match (result, &open.target) { - (Some(DialogResult::Ok(r)), Target::Answer { parent, key }) => dialogs.with(|h| h.answer_color(*parent, key, r.picked.color)), + (Some(DialogResult::Ok(r)), Target::Answer { parent, key }) => { + if !super::save_for_web::take_palette_pick(app, *parent, key, open.start, r.picked.color) { + dialogs.with(|h| h.answer_color(*parent, key, r.picked.color)); + } + } (Some(DialogResult::Ok(r)), _) => { if let Err(e) = commit(app, open, preview, &r.picked) { app.status(e); diff --git a/crates/ui-egui/src/dialogs/save_for_web.rs b/crates/ui-egui/src/dialogs/save_for_web.rs index b338d45611..aaaf3d4e1c 100644 --- a/crates/ui-egui/src/dialogs/save_for_web.rs +++ b/crates/ui-egui/src/dialogs/save_for_web.rs @@ -19,10 +19,12 @@ use vectorcraft_render::encode::quantize::Reduction; use craft::behavior::PixelSize; use craft::host::PickRequest; +use craft::theme::Srgba; use craft::ui::dialog::{DialogId, DialogResult, StackDialog}; use craft::ui::patterns::form_dialogs::{ BrowserPreview, ColorTable, ColorTableEdit, ColorTableEvent, HostedSaveForWeb, OptimizeAnswer, OptimizeRequest, OptimizeScope, OptimizeStart, - SaveForWebOptions, SaveForWebResult, WantedVariant, WebDocument, WebFormat, WebPreset, WebPresetEvent, WebSlice, WebSlices, WebVariant, + PALETTE_COLOR_KEY, SaveForWebOptions, SaveForWebResult, WantedVariant, WebDocument, WebFormat, WebPreset, WebPresetEvent, WebSlice, WebSlices, + WebVariant, }; use craft::ui::primitives::{Revision, TextureStore, TextureStoreOptions}; use craft::ui::runtime::requests::PathRequest; @@ -432,7 +434,7 @@ fn on_dialog(host: &craft::ui::shell::WindowDialogs, f: impl FnOnce(&mut Host /// Answers the open dialog once per frame: its result when it closed, else its requests. /// Colour requests (the matte, a palette cell) are routed by the host-wide colour picker routing; -/// a palette answer comes back as a `Shift` table event. +/// a palette cell's pick is applied to the table by [`take_palette_pick`]. pub(crate) fn pump(app: &mut VectorcraftApp, ctx: &egui::Context) { let Some(host) = app.dialogs() else { return }; match host.with(|h| h.take::()) { @@ -511,12 +513,7 @@ fn answer_variants(app: &mut VectorcraftApp, ctx: &egui::Context, host: &craft:: /// Applies the colour table edits the dialog filed. A Delete clears the dialog's colour selection. fn edit_table(app: &mut VectorcraftApp, ctx: &egui::Context, host: &craft::ui::shell::WindowDialogs, asked: &Asked) { - let shown = app - .session - .web_settings(&settings_of(&asked.options, &app.web_export.table, None)) - .and_then(|s| encoded(app, &s)) - .map(|o| o.colors.iter().map(|c| c.source).collect::>()); - let shown = match shown { + let shown = match shown_colors(app, &asked.options) { Ok(shown) => shown, Err(e) => return app.status(e), }; @@ -533,6 +530,36 @@ fn edit_table(app: &mut VectorcraftApp, ctx: &egui::Context, host: &craft::ui::s } } +/// The source colours of the palette the dialog's settings `options` show, with the table as it stands. +fn shown_colors(app: &mut VectorcraftApp, options: &SaveForWebOptions) -> Result, String> { + let settings = app.session.web_settings(&settings_of(options, &app.web_export.table, None))?; + Ok(encoded(app, &settings)?.colors.iter().map(|c| c.source).collect()) +} + +/// The Color Picker's OK for the colour table cell `key` of the open dialog `parent`: the cell's colour `from` +/// is shifted to `to` in the table at once, so Done or Save in the dialog's next pass keeps the shift. A colour +/// the palette no longer shows is not shifted, and a refused shift shows in the status line. `false` when +/// `parent` is not Save for Web or `key` is not its palette, and the picker answers the row instead. +pub(crate) fn take_palette_pick(app: &mut VectorcraftApp, parent: DialogId, key: &str, from: Srgba, to: Srgba) -> bool { + let Some(host) = app.dialogs() else { return false }; + if key != PALETTE_COLOR_KEY { + return false; + } + let Some(options) = host.with(|h| h.get_mut_by_id::(parent).map(|d| d.current().clone())) else { + return false; + }; + let rgb = |c: Srgba| { + let [r, g, b, _] = c.to_rgba().0; + [r, g, b] + }; + let edit = ColorTableEdit::Shift(rgb(to)); + let shifted = shown_colors(app, &options).and_then(|shown| color_table::apply(&mut app.web_export.table, &edit, &[rgb(from)], &shown)); + if let Err(e) = shifted { + app.status(e); + } + true +} + /// Runs what the preset list asked for and shows a failure in the status line. fn store_presets(app: &mut VectorcraftApp, events: Vec) { for event in events { diff --git a/crates/ui-egui/src/dialogs/save_for_web/color_table.rs b/crates/ui-egui/src/dialogs/save_for_web/color_table.rs index 280fcae18a..39b03bc9d9 100644 --- a/crates/ui-egui/src/dialogs/save_for_web/color_table.rs +++ b/crates/ui-egui/src/dialogs/save_for_web/color_table.rs @@ -241,9 +241,17 @@ pub(crate) fn restore(table: &mut Value) { } /// What the table shows of `table`: its locked, transparent and shifted colours. An entry that is -/// not a colour is skipped. +/// not a colour is skipped, and a colour written more than once in a list is listed once. pub(crate) fn marks(table: &Value) -> TableMarks { - let colors = |key: &str| list(table, key).iter().filter_map(|c| parse(c)).collect(); + let colors = |key: &str| { + let mut out: Vec<[u8; 3]> = Vec::new(); + for c in list(table, key).iter().filter_map(|c| parse(c)) { + if !out.contains(&c) { + out.push(c); + } + } + out + }; let shifted = shifts(table).iter().filter_map(|(k, v)| Some((parse(k)?, parse(v.as_str()?)?))).collect(); // PLAN: TableMarks lacks `web_shifted` (ex.W9 request); the Web Shift/Unshift label needs it. let mut marks = TableMarks::default(); diff --git a/crates/ui-egui/src/dialogs/save_for_web/tests_table.rs b/crates/ui-egui/src/dialogs/save_for_web/tests_table.rs index 60b12ec807..6dabd4c119 100644 --- a/crates/ui-egui/src/dialogs/save_for_web/tests_table.rs +++ b/crates/ui-egui/src/dialogs/save_for_web/tests_table.rs @@ -279,6 +279,35 @@ fn a_picked_color_becomes_a_shift_and_cancel_shifts_nothing() { assert_eq!(app.web_export.table["shifted"], json!({"#0000ff": "#00ff00"})); } +/// Done right after the Color Picker's OK, before the dialog draws again, remembers the picked shift. +#[test] +fn done_right_after_the_color_picker_remembers_the_shift() { + let dir = vectorcraft_testkit::temp_dir("sfw-shift-done"); + let (mut app, _) = app(&dir, false); + app.run("shape.rectangle", json!({"x": 40, "y": 0, "width": 20, "height": 40})).unwrap(); + app.run("paint.setFill", json!({"color": "#0000ff"})).unwrap(); + app.run("file.saveForWeb", json!({})).unwrap(); + for (k, v) in [("format", json!("gif")), ("antiAlias", json!("none")), ("dither", json!("none"))] { + set(&mut app, k, v); + } + let ctx = app.ui_ctx.clone().expect("the app has a window"); + crate::dialogs::host::pump(&mut app, &ctx); + let picker = open_cell(&mut app, &ctx, "#0000ff"); + host(&app).with(|h| h.set_json_field(&ctx, picker, "color", json!("#00ff00"))).unwrap(); + host(&app).with(|h| h.confirm_by_id(&ctx, picker)); + // The frame that settles the picker, then Done before the dialog's next pass. + app_frame(&mut app, &ctx, vec![]); + set(&mut app, "choice", json!("done")); + let dialog = id(&app); + host(&app).with(|h| h.confirm_by_id(&ctx, dialog)); + for _ in 0..3 { + app_frame(&mut app, &ctx, vec![]); + } + assert!(host(&app).with(|h| h.get::().is_none()), "Done closes the dialog"); + let remembered = app.session.last_web_settings().color_table.shifted; + assert_eq!(remembered.get("#0000ff").map(String::as_str), Some("#00ff00")); +} + #[test] fn restore_brings_back_a_preview_that_failed() { let dir = vectorcraft_testkit::temp_dir("sfw-restore-table"); From dd37e3c14bf92f10d893088251b889f52e56c30a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 18:20:37 -0800 Subject: [PATCH 17/26] Tests: Find Objects during a drag journals the drag's own selection After Find Objects with `select` runs during a drag, the drag's own selection is journaled before its release, so the expected journal is document.find, select.set, shape.rectangle. --- crates/engine/src/tests/interaction_commands.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/tests/interaction_commands.rs b/crates/engine/src/tests/interaction_commands.rs index 5234ea52ac..1c24f26440 100644 --- a/crates/engine/src/tests/interaction_commands.rs +++ b/crates/engine/src/tests/interaction_commands.rs @@ -448,7 +448,8 @@ fn find_objects_with_select_during_a_drag_skips_the_drag_preview() { assert_eq!(r["matches"][0]["id"], other.0, "{at}: {r}"); pointer(&mut s, PointerKind::Up, 200.0, 180.0); assert_eq!(objects(&s), 2, "{at}: the release draws the rectangle"); - assert_eq!(journaled(&s, start), ["document.find", "shape.rectangle"], "{at}"); + // The drag's own selection is journaled after the find, so the release replays on it. + assert_eq!(journaled(&s, start), ["document.find", "select.set", "shape.rectangle"], "{at}"); let (mut replayed, _) = session(real_time); replay_from(&s, start, &mut replayed); assert_eq!(objects(&replayed), 2, "{at}"); From 0a85db2eef1bc312e183566254ba86f8fdcb3287 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 19:06:21 -0800 Subject: [PATCH 18/26] Window menu: the task bar's Show Properties Panel keeps Properties showing More Options > Show Properties Panel fired window.panel {panel: "properties"}, which now matched the Window > Properties row and took its toggle, so a click hid a showing Properties panel. The row names toggle: false, which never matches a Window row, and window.panel with toggle: false leaves a panel that can be seen as it is, also in a flyout or a floating window. The params text and docs/mcp.md describe it. The Window menu click test uses Libraries, a docked panel with no function key, so it fails when a click does not take the row's toggle. --- crates/mcp/src/ui_catalog.rs | 2 +- crates/ui-egui/src/canvas/task_bar.rs | 8 ++++- crates/ui-egui/src/menus/entries.rs | 15 ++++---- crates/ui-egui/src/menus/ui_commands.rs | 2 +- crates/ui-egui/src/panel_docking.rs | 6 +++- crates/ui-egui/src/shortcuts/tests.rs | 46 +++++++++++++++++++------ docs/mcp.md | 3 +- 7 files changed, 60 insertions(+), 22 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index ebbf43c814..c5c251b37c 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -739,7 +739,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "window.panel", "Show Panel", "", - "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", + "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; toggle false leaves a panel that can be seen as it is, also in a flyout or a floating window; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", ), ( "window.panel.layout", diff --git a/crates/ui-egui/src/canvas/task_bar.rs b/crates/ui-egui/src/canvas/task_bar.rs index 5ec9e92382..22f0836d39 100644 --- a/crates/ui-egui/src/canvas/task_bar.rs +++ b/crates/ui-egui/src/canvas/task_bar.rs @@ -425,6 +425,12 @@ pub(crate) fn menu_states(app: &VectorcraftApp, states: &mut CommandStates) { states.set(CommandRef::new("window.taskBar.resetActions"), CommandState::new().enabled(!app.ui.task_bar_hidden_actions.is_empty())); } +/// More Options › Show Properties Panel. It names `toggle: false`, so a click shows the panel and leaves a showing one +/// showing, docked, floating or in a flyout; it does not run the Window menu row's toggle ([`crate::menus::is_row_of`]). +pub(crate) fn show_properties() -> CommandRef { + CommandRef::with_params("window.panel", json!({"panel": "properties", "toggle": false})) +} + /// The rows More Options shows after the framework's own: Bar Actions, Reset Bar Actions and Show Properties Panel. fn more_rows(offer: &Offer) -> Vec { let actions = offer @@ -437,7 +443,7 @@ fn more_rows(offer: &Offer) -> Vec { PanelRow::Submenu(Label::from(tl!("Bar Actions")), actions), PanelRow::Command(CommandRef::new("window.taskBar.resetActions")), PanelRow::Separator, - PanelRow::Command(CommandRef::with_params("window.panel", json!({"panel": "properties"}))), + PanelRow::Command(show_properties()), ] } diff --git a/crates/ui-egui/src/menus/entries.rs b/crates/ui-egui/src/menus/entries.rs index d90b4b9872..820f304cb4 100644 --- a/crates/ui-egui/src/menus/entries.rs +++ b/crates/ui-egui/src/menus/entries.rs @@ -29,6 +29,9 @@ pub struct MenuEntry { pub shown_path: Vec, } +/// The command id of the menu rows that show a panel. +const PANEL_COMMAND: &str = "window.panel"; + /// Flattened menu for `ui.menu.list`. A row that shows a panel of the Window menu, there or in another menu (Type › /// Glyphs), lists the params a click on it runs: `window.panel` with `toggle: true`, which puts a showing panel away /// ([`is_row_of`]). @@ -39,11 +42,11 @@ pub fn menu_entries(app: &VectorcraftApp) -> Vec { } let window_panels: Vec = out .iter() - .filter(|e| e.path.first().is_some_and(|t| t == "Window") && e.command.as_deref() == Some(PANEL)) + .filter(|e| e.path.first().is_some_and(|t| t == "Window") && e.command.as_deref() == Some(PANEL_COMMAND)) .map(|e| e.params.clone()) .collect(); for e in &mut out { - if e.command.as_deref() == Some(PANEL) + if e.command.as_deref() == Some(PANEL_COMMAND) && window_panels.contains(&e.params) && let Some(params) = e.params.as_object_mut() { @@ -53,11 +56,9 @@ pub fn menu_entries(app: &VectorcraftApp) -> Vec { out } -/// The command of the rows that show a panel. -const PANEL: &str = "window.panel"; - /// Whether `e` is the row of the menu item that runs command `id` with `params`: the same command and params, or a -/// panel row that [`menu_entries`] lists with `toggle: true` added. +/// panel row that [`menu_entries`] lists with `toggle: true` added. Another menu's row that shows a panel without +/// toggling it names `toggle: false` (the task bar's Show Properties Panel), so it does not match a Window row. pub fn is_row_of(e: &MenuEntry, id: &str, params: &Value) -> bool { if e.command.as_deref() != Some(id) { return false; @@ -66,7 +67,7 @@ pub fn is_row_of(e: &MenuEntry, id: &str, params: &Value) -> bool { return true; } let mut listed = e.params.clone(); - id == PANEL + id == PANEL_COMMAND && params.get("toggle").is_none() && listed.as_object_mut().and_then(|o| o.remove("toggle")) == Some(Value::Bool(true)) && listed == *params diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 77b585a69b..92d77a9090 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -740,7 +740,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "window.panel", "Show Panel", "", - "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", + "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; toggle false leaves a panel that can be seen as it is, also in a flyout or a floating window; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", ), ( "window.panel.layout", diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs index d06f38c22b..da47985003 100644 --- a/crates/ui-egui/src/panel_docking.rs +++ b/crates/ui-egui/src/panel_docking.rs @@ -413,13 +413,17 @@ fn ui_dock(app: &mut VectorcraftApp, params: &Value) -> Result { /// library panel or a panel the dock has no place for floats. A flyout or floating panel is put /// away only while it can be seen ([`visible`]): with the dock hidden by Tab or Shift+Tab, the /// dock shows again with the panel where it was, and the toolbar and Control bar stay as they are. -/// Presentation Mode hides every panel, so there the command fails and changes nothing. +/// Presentation Mode hides every panel, so there the command fails and changes nothing. With +/// `toggle: false` a panel that can be seen stays as it is ([`reveal_panel`]). fn show_panel(app: &mut VectorcraftApp, params: &Value) -> Result { let raw = params.get("panel").and_then(Value::as_str).unwrap_or_default(); let panel = normalize(raw).ok_or_else(|| format!("unknown panel `{raw}`"))?; if app.ui.screen_mode >= 3 { return Err("panels can't be shown in Presentation Mode".into()); } + if params.get("toggle") == Some(&Value::Bool(false)) { + return reveal_panel(app, panel); + } place_panel(app, panel) } diff --git a/crates/ui-egui/src/shortcuts/tests.rs b/crates/ui-egui/src/shortcuts/tests.rs index 49d09ddf13..c65d8056eb 100644 --- a/crates/ui-egui/src/shortcuts/tests.rs +++ b/crates/ui-egui/src/shortcuts/tests.rs @@ -255,19 +255,22 @@ fn window_menu_panel_rows_show_their_panels_shortcuts() { let rows: Vec = app.menus.bar.items().into_iter().filter(|it| it.command.id == "window.panel").map(|it| it.command.clone()).collect(); assert!(!rows.is_empty(), "the Window menu lists panels"); - let mut shown = 0; + let mut with_keys = 0; for row in &rows { let panel = row.params["panel"].as_str().expect("a panel row names its panel"); let entry = crate::keymap::command_of(&format!("panel:{panel}")); let chord = craft::ui::runtime::commands::chord(&ctx, row); assert_eq!(chord, craft::ui::runtime::commands::chord(&ctx, &entry), "{panel}: the row shows its shortcut's chord"); - shown += usize::from(chord.is_some()); + if crate::shortcut_editor::PANEL_SHORTCUTS.iter().any(|(p, _)| *p == panel) { + assert!(chord.is_some(), "{panel} has a default key, and its row shows it"); + with_keys += 1; + } } - let with_keys = crate::shortcut_editor::PANEL_SHORTCUTS.iter().filter(|(panel, _)| rows.iter().any(|r| r.params["panel"] == *panel)).count(); - assert!(with_keys > 0 && shown >= with_keys, "{shown} rows show a chord, {with_keys} panels have a default key"); + assert!(with_keys > 0, "some listed panels have a default key"); } -/// A click on a Window menu row toggles its panel: it puts a showing panel away and shows it again. +/// A click on a Window menu row toggles its panel: it puts a showing panel away and shows it again. Libraries is +/// docked in front with no function key, so neither its flyout nor its shortcut toggles it. #[test] fn a_window_menu_click_toggles_its_panel() { use craft::ui::runtime::commands::{FirePhase, FireSource, Fired}; @@ -278,20 +281,43 @@ fn a_window_menu_click_toggles_its_panel() { .bar .items() .into_iter() - .find(|it| it.command.id == "window.panel" && it.command.params["panel"] == "layers") + .find(|it| it.command.id == "window.panel" && it.command.params["panel"] == "libraries") .map(|it| it.command.clone()); - let row = row.expect("a Window › Layers row"); - let before = crate::panel_docking::showing(&app.ui, "layers"); + let row = row.expect("a Window › Libraries row"); + let before = crate::panel_docking::showing(&app.ui, "libraries"); let click = |app: &mut VectorcraftApp| { crate::shortcuts::run_fired(app, &ctx, &Fired::new(row.clone(), FireSource::Menu, FirePhase::Press, 0.0)); key_frame(app, &ctx, vec![]); - crate::panel_docking::showing(&app.ui, "layers") + crate::panel_docking::showing(&app.ui, "libraries") }; let once = click(&mut app); - assert_ne!(once, before, "the first click toggles Layers"); + assert_ne!(once, before, "the first click toggles Libraries"); assert_eq!(click(&mut app), before, "the second click toggles it back"); } +/// A click on the task bar's More Options › Show Properties Panel leaves a showing Properties panel showing, docked +/// and in an icon column's flyout: it does not take the toggle of Window › Properties. +#[test] +fn the_task_bar_show_properties_row_keeps_properties_showing() { + use craft::ui::runtime::commands::{FirePhase, FireSource, Fired}; + let mut app = new_app(); + let ctx = ready(&mut app); + let row = crate::canvas::task_bar::show_properties(); + let click = |app: &mut VectorcraftApp| { + crate::shortcuts::run_fired(app, &ctx, &Fired::new(row.clone(), FireSource::Menu, FirePhase::Press, 0.0)); + key_frame(app, &ctx, vec![]); + crate::panel_docking::showing(&app.ui, "properties") + }; + assert!(click(&mut app), "the first click shows Properties"); + assert!(click(&mut app), "a second click leaves Properties showing"); + app.run("window.collapseDock", json!({ "collapsed": true })).expect("the dock collapses to icons"); + key_frame(&mut app, &ctx, vec![]); + assert!(click(&mut app), "a click opens the Properties flyout"); + assert!(click(&mut app), "a second click leaves the flyout open"); + app.run("window.panel", row.params.clone()).expect("the command runs from automation"); + assert!(crate::panel_docking::showing(&app.ui, "properties"), "the command leaves the flyout open from automation too"); +} + /// `ui.menu.list` lists a Window menu panel row with the toggle a click on it runs, and a plug-in's row that shows a /// panel the Window menu does not list (Object › Plug-ins › Packaging Tools › Fold Lines) without one. #[test] diff --git a/docs/mcp.md b/docs/mcp.md index 87301d0bf5..40aff43fdb 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2142,7 +2142,8 @@ and the action still plays. `Session::replay` plays a journal the same way. The `color` or `channel` it can't read. `window.panel` refuses every request in Presentation Mode, which hides every panel, and changes nothing. With -`toggle` it hides only a panel that can be seen, which is the panel the Window menu checks. While Tab or Shift+Tab +`toggle` it hides only a panel that can be seen, which is the panel the Window menu checks. With `toggle: false` a panel +that can be seen stays as it is, also in a flyout or a floating window. While Tab or Shift+Tab hides the dock, no panel is checked, and the panel shows again with the dock in its earlier place; the toolbar and the Control bar stay as they are. From 510119e7c1c21c9fb930931b0600a870bca73ba3 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 19:49:40 -0800 Subject: [PATCH 19/26] Window menu: panel rows carry their toggle and show the shortcut's chord The Window menu rows run window.panel {panel, toggle: true} again, as on main, so a menu row elsewhere that runs window.panel {panel} (the Contextual Task Bar's More Options > Show Properties Panel) no longer takes a Window row's toggle. Each panel row now sets its shortcut to the chord of the panel's shortcut entry (panel:, the lookup ui.menu.list uses), as the Settings rows set Preferences' chord. The menus are built again when the window's keymap changes, so the first frame's menus, built before the keymap, do not stay without chords. canvas/task_bar.rs, menus/entries.rs and the click lookup in shortcuts.rs are back to main, and window.panel has no toggle: false case. --- crates/mcp/src/ui_catalog.rs | 2 +- crates/ui-egui/src/canvas/task_bar.rs | 8 +---- crates/ui-egui/src/menus.rs | 2 +- crates/ui-egui/src/menus/entries.rs | 37 +--------------------- crates/ui-egui/src/menus/model.rs | 12 ++++++- crates/ui-egui/src/menus/tree.rs | 4 +-- crates/ui-egui/src/menus/ui_commands.rs | 2 +- crates/ui-egui/src/panel_docking.rs | 6 +--- crates/ui-egui/src/shortcuts.rs | 7 ++--- crates/ui-egui/src/shortcuts/tests.rs | 42 +++++++++---------------- docs/mcp.md | 3 +- 11 files changed, 37 insertions(+), 88 deletions(-) diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index c5c251b37c..ebbf43c814 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -739,7 +739,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "window.panel", "Show Panel", "", - "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; toggle false leaves a panel that can be seen as it is, also in a flyout or a floating window; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", + "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", ), ( "window.panel.layout", diff --git a/crates/ui-egui/src/canvas/task_bar.rs b/crates/ui-egui/src/canvas/task_bar.rs index 22f0836d39..5ec9e92382 100644 --- a/crates/ui-egui/src/canvas/task_bar.rs +++ b/crates/ui-egui/src/canvas/task_bar.rs @@ -425,12 +425,6 @@ pub(crate) fn menu_states(app: &VectorcraftApp, states: &mut CommandStates) { states.set(CommandRef::new("window.taskBar.resetActions"), CommandState::new().enabled(!app.ui.task_bar_hidden_actions.is_empty())); } -/// More Options › Show Properties Panel. It names `toggle: false`, so a click shows the panel and leaves a showing one -/// showing, docked, floating or in a flyout; it does not run the Window menu row's toggle ([`crate::menus::is_row_of`]). -pub(crate) fn show_properties() -> CommandRef { - CommandRef::with_params("window.panel", json!({"panel": "properties", "toggle": false})) -} - /// The rows More Options shows after the framework's own: Bar Actions, Reset Bar Actions and Show Properties Panel. fn more_rows(offer: &Offer) -> Vec { let actions = offer @@ -443,7 +437,7 @@ fn more_rows(offer: &Offer) -> Vec { PanelRow::Submenu(Label::from(tl!("Bar Actions")), actions), PanelRow::Command(CommandRef::new("window.taskBar.resetActions")), PanelRow::Separator, - PanelRow::Command(show_properties()), + PanelRow::Command(CommandRef::with_params("window.panel", json!({"panel": "properties"}))), ] } diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index b7f833c9ac..7d003be560 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -63,7 +63,7 @@ mod ui_commands; pub use context::context_items; #[cfg(test)] use entries::flatten; -pub use entries::{InsertableItem, MenuEntry, context_entries, insertable, insertable_items, is_row_of, menu_entries, plays_in_app, shown_label}; +pub use entries::{InsertableItem, MenuEntry, context_entries, insertable, insertable_items, menu_entries, plays_in_app, shown_label}; pub(crate) use invoke::graph_dialog; pub use invoke::{click_target, invoke}; pub(crate) use labels::lists_plugin; diff --git a/crates/ui-egui/src/menus/entries.rs b/crates/ui-egui/src/menus/entries.rs index 820f304cb4..6524edfd21 100644 --- a/crates/ui-egui/src/menus/entries.rs +++ b/crates/ui-egui/src/menus/entries.rs @@ -29,50 +29,15 @@ pub struct MenuEntry { pub shown_path: Vec, } -/// The command id of the menu rows that show a panel. -const PANEL_COMMAND: &str = "window.panel"; - -/// Flattened menu for `ui.menu.list`. A row that shows a panel of the Window menu, there or in another menu (Type › -/// Glyphs), lists the params a click on it runs: `window.panel` with `toggle: true`, which puts a showing panel away -/// ([`is_row_of`]). +/// Flattened menu for `ui.menu.list`. pub fn menu_entries(app: &VectorcraftApp) -> Vec { let mut out = vec![]; for (title, items) in menu_tree_named(app.session.prefs.font_names_in_english, &Listed::of(app)) { flatten(app, vec![title.to_string()], vec![crate::i18n::t(title).to_string()], &items, &mut out); } - let window_panels: Vec = out - .iter() - .filter(|e| e.path.first().is_some_and(|t| t == "Window") && e.command.as_deref() == Some(PANEL_COMMAND)) - .map(|e| e.params.clone()) - .collect(); - for e in &mut out { - if e.command.as_deref() == Some(PANEL_COMMAND) - && window_panels.contains(&e.params) - && let Some(params) = e.params.as_object_mut() - { - params.entry("toggle").or_insert(Value::Bool(true)); - } - } out } -/// Whether `e` is the row of the menu item that runs command `id` with `params`: the same command and params, or a -/// panel row that [`menu_entries`] lists with `toggle: true` added. Another menu's row that shows a panel without -/// toggling it names `toggle: false` (the task bar's Show Properties Panel), so it does not match a Window row. -pub fn is_row_of(e: &MenuEntry, id: &str, params: &Value) -> bool { - if e.command.as_deref() != Some(id) { - return false; - } - if e.params == *params { - return true; - } - let mut listed = e.params.clone(); - id == PANEL_COMMAND - && params.get("toggle").is_none() - && listed.as_object_mut().and_then(|o| o.remove("toggle")) == Some(Value::Bool(true)) - && listed == *params -} - /// Flattened canvas context menu for `ui.contextMenu.list` (paths are its submenus). pub fn context_entries(app: &VectorcraftApp) -> Vec { let mut out = vec![]; diff --git a/crates/ui-egui/src/menus/model.rs b/crates/ui-egui/src/menus/model.rs index 9fdbeb7d84..6052b9e89c 100644 --- a/crates/ui-egui/src/menus/model.rs +++ b/crates/ui-egui/src/menus/model.rs @@ -86,6 +86,9 @@ pub(crate) fn state_key(app: &VectorcraftApp, input: Option) -> u64 { let mut h = DefaultHasher::new(); input.hash(&mut h); app.run_count.hash(&mut h); + // The window's keymap, which the panel rows read their shortcuts from (`Build::decorate`): the framework builds it + // after the first frame's menus, and builds a new one when the bindings or the catalog change. + app.ui_ctx.as_ref().and_then(craft::ui::runtime::commands::keymap).map(|k| std::sync::Arc::as_ptr(&k).addr()).hash(&mut h); let s = &app.session; (s.journal.len(), s.active_index(), s.clipboard.is_empty(), s.tool_composing()).hash(&mut h); if let Some(d) = s.active() { @@ -463,11 +466,18 @@ impl Build<'_> { item_title(self.app, self.lang, id, params, label) } - /// The alternates (a modifier held as the row is chosen) and the font sample of a row. + /// The alternates (a modifier held as the row is chosen), the font sample and the shortcut of a row. fn decorate(&self, item: Item, id: &str, params: &Value) -> Item { let run_with = |mods: Mods, p: Value| Alternate::new(mods, CommandRef::with_params(id, p)); let held = |shift: bool, alt: bool| Mods { cmd: false, ctrl: false, alt, shift }; match id { + // A panel row shows the chord of the panel's shortcut (`panel:`), which binds `window.panel {panel}`; + // a Window row runs it with `toggle: true`, so the framework finds no chord for the row's own command. + "window.panel" => { + let mut item = item; + item.shortcut = super::labels::item_shortcut(self.app, id, params); + item + } "ui.expandDialog" => item.alternate(run_with(held(false, true), json!({ "immediate": true }))), crate::addons::select::link_status::COMMAND => { item.alternate(run_with(held(true, false), crate::addons::select::link_status::with_shift(params.clone()))) diff --git a/crates/ui-egui/src/menus/tree.rs b/crates/ui-egui/src/menus/tree.rs index fa5e15d238..13b33dde44 100644 --- a/crates/ui-egui/src/menus/tree.rs +++ b/crates/ui-egui/src/menus/tree.rs @@ -45,9 +45,7 @@ impl Listed { } pub fn menu_tree_named(english_names: bool, listed: &Listed) -> Vec<(&'static str, Vec)> { - // A Window row names the command the panel's shortcut runs, so it shows that shortcut; a click toggles the panel - // (`menu_entries` lists the row with `toggle: true`). - let panel = |label: &'static str, id: &'static str| cp(label, "window.panel", json!({ "panel": id })); + let panel = |label: &'static str, id: &'static str| cp(label, "window.panel", json!({ "panel": id, "toggle": true })); vec![ ( // The application menu, shown on macOS only: the layout merges it with the items the diff --git a/crates/ui-egui/src/menus/ui_commands.rs b/crates/ui-egui/src/menus/ui_commands.rs index 92d77a9090..77b585a69b 100644 --- a/crates/ui-egui/src/menus/ui_commands.rs +++ b/crates/ui-egui/src/menus/ui_commands.rs @@ -740,7 +740,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "window.panel", "Show Panel", "", - "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; toggle false leaves a panel that can be seen as it is, also in a flyout or a floating window; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", + "{panel: id, toggle?: bool} e.g. layers, swatches, stroke (case-insensitive; display labels like \"Layers\" work too); toggle (the Window menu) hides a panel that can be seen, and shows it again where it was; with the dock hidden by Tab or Shift+Tab, the dock shows again with the panel in front, leaving the toolbar and Control bar as they are; fails and changes nothing in Presentation Mode, which hides every panel", ), ( "window.panel.layout", diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs index da47985003..d06f38c22b 100644 --- a/crates/ui-egui/src/panel_docking.rs +++ b/crates/ui-egui/src/panel_docking.rs @@ -413,17 +413,13 @@ fn ui_dock(app: &mut VectorcraftApp, params: &Value) -> Result { /// library panel or a panel the dock has no place for floats. A flyout or floating panel is put /// away only while it can be seen ([`visible`]): with the dock hidden by Tab or Shift+Tab, the /// dock shows again with the panel where it was, and the toolbar and Control bar stay as they are. -/// Presentation Mode hides every panel, so there the command fails and changes nothing. With -/// `toggle: false` a panel that can be seen stays as it is ([`reveal_panel`]). +/// Presentation Mode hides every panel, so there the command fails and changes nothing. fn show_panel(app: &mut VectorcraftApp, params: &Value) -> Result { let raw = params.get("panel").and_then(Value::as_str).unwrap_or_default(); let panel = normalize(raw).ok_or_else(|| format!("unknown panel `{raw}`"))?; if app.ui.screen_mode >= 3 { return Err("panels can't be shown in Presentation Mode".into()); } - if params.get("toggle") == Some(&Value::Bool(false)) { - return reveal_panel(app, panel); - } place_panel(app, panel) } diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs index 7ee393527f..eaa0065ba4 100644 --- a/crates/ui-egui/src/shortcuts.rs +++ b/crates/ui-egui/src/shortcuts.rs @@ -276,8 +276,7 @@ fn menu_target(c: &CommandRef) -> Option<(String, serde_json::Value)> { } /// What a click on the menu bar's or the canvas menu's row `c` runs ([`crate::menus::click_target`]): a "…" row with -/// params opens its dialog on them (Clean Up…), and a row of a Window menu panel runs the params it is listed with -/// (`toggle: true`, [`crate::menus::is_row_of`]). `None` for a command that no menu fired. +/// params opens its dialog on them (Clean Up…). `None` for a command that no menu fired. fn clicked_row(app: &VectorcraftApp, source: FireSource, c: &CommandRef) -> Option<(String, serde_json::Value)> { if source != FireSource::Menu || c.params.as_object().is_none_or(serde_json::Map::is_empty) { return None; @@ -285,8 +284,8 @@ fn clicked_row(app: &VectorcraftApp, source: FireSource, c: &CommandRef) -> Opti let row = crate::menus::menu_entries(app) .into_iter() .chain(crate::menus::context_entries(app)) - .find(|e| crate::menus::is_row_of(e, &c.id, &c.params))?; - Some(crate::menus::click_target(&row.label, &c.id, &row.params)) + .find(|e| e.command.as_deref() == Some(c.id.as_str()) && e.params == c.params)?; + Some(crate::menus::click_target(&row.label, &c.id, &c.params)) } /// Params used when a shortcut invokes its command. The named panel function keys retain their diff --git a/crates/ui-egui/src/shortcuts/tests.rs b/crates/ui-egui/src/shortcuts/tests.rs index c65d8056eb..e4b424defd 100644 --- a/crates/ui-egui/src/shortcuts/tests.rs +++ b/crates/ui-egui/src/shortcuts/tests.rs @@ -247,19 +247,26 @@ fn named_panel_default_chords_toggle_their_panels() { } /// Each Window menu row that shows a panel shows the chord of that panel's shortcut, as production's did, and the -/// rows of the panels with a default key show one. +/// rows of the panels with a default key show one. The first frame builds the keymap after its menus, so the menus of +/// the next frame show the chords. #[test] fn window_menu_panel_rows_show_their_panels_shortcuts() { let mut app = new_app(); let ctx = ready(&mut app); - let rows: Vec = - app.menus.bar.items().into_iter().filter(|it| it.command.id == "window.panel").map(|it| it.command.clone()).collect(); + key_frame(&mut app, &ctx, vec![]); + let rows: Vec<(craft::keymap::CommandRef, Option)> = app + .menus + .bar + .items() + .into_iter() + .filter(|it| it.command.id == "window.panel" && it.command.params["toggle"] == true) + .map(|it| (it.command.clone(), it.shortcut)) + .collect(); assert!(!rows.is_empty(), "the Window menu lists panels"); let mut with_keys = 0; - for row in &rows { + for (row, chord) in rows { let panel = row.params["panel"].as_str().expect("a panel row names its panel"); let entry = crate::keymap::command_of(&format!("panel:{panel}")); - let chord = craft::ui::runtime::commands::chord(&ctx, row); assert_eq!(chord, craft::ui::runtime::commands::chord(&ctx, &entry), "{panel}: the row shows its shortcut's chord"); if crate::shortcut_editor::PANEL_SHORTCUTS.iter().any(|(p, _)| *p == panel) { assert!(chord.is_some(), "{panel} has a default key, and its row shows it"); @@ -295,14 +302,14 @@ fn a_window_menu_click_toggles_its_panel() { assert_eq!(click(&mut app), before, "the second click toggles it back"); } -/// A click on the task bar's More Options › Show Properties Panel leaves a showing Properties panel showing, docked -/// and in an icon column's flyout: it does not take the toggle of Window › Properties. +/// A click on the task bar's More Options › Show Properties Panel, a menu row that runs `window.panel {panel: +/// "properties"}`, leaves a showing docked Properties panel showing: it does not take the toggle of Window › Properties. #[test] fn the_task_bar_show_properties_row_keeps_properties_showing() { use craft::ui::runtime::commands::{FirePhase, FireSource, Fired}; let mut app = new_app(); let ctx = ready(&mut app); - let row = crate::canvas::task_bar::show_properties(); + let row = craft::keymap::CommandRef::with_params("window.panel", json!({ "panel": "properties" })); let click = |app: &mut VectorcraftApp| { crate::shortcuts::run_fired(app, &ctx, &Fired::new(row.clone(), FireSource::Menu, FirePhase::Press, 0.0)); key_frame(app, &ctx, vec![]); @@ -310,25 +317,6 @@ fn the_task_bar_show_properties_row_keeps_properties_showing() { }; assert!(click(&mut app), "the first click shows Properties"); assert!(click(&mut app), "a second click leaves Properties showing"); - app.run("window.collapseDock", json!({ "collapsed": true })).expect("the dock collapses to icons"); - key_frame(&mut app, &ctx, vec![]); - assert!(click(&mut app), "a click opens the Properties flyout"); - assert!(click(&mut app), "a second click leaves the flyout open"); - app.run("window.panel", row.params.clone()).expect("the command runs from automation"); - assert!(crate::panel_docking::showing(&app.ui, "properties"), "the command leaves the flyout open from automation too"); -} - -/// `ui.menu.list` lists a Window menu panel row with the toggle a click on it runs, and a plug-in's row that shows a -/// panel the Window menu does not list (Object › Plug-ins › Packaging Tools › Fold Lines) without one. -#[test] -fn listed_window_rows_toggle_and_plugin_panel_rows_do_not() { - let app = new_app(); - let entries = crate::menus::menu_entries(&app); - let row = - |panel: &str| entries.iter().find(|e| e.command.as_deref() == Some("window.panel") && e.params["panel"] == panel).map(|e| e.params.clone()); - assert_eq!(row("layers").map(|p| p["toggle"].clone()), Some(json!(true)), "Window › Layers toggles"); - let fold = row(crate::addons::packaging::ID).expect("a Fold Lines row"); - assert!(fold.get("toggle").is_none(), "Fold Lines shows its panel: {fold}"); } /// A shortcut on a panel without a function key of its own runs `window.panel` with the params it has: no toggle is diff --git a/docs/mcp.md b/docs/mcp.md index 40aff43fdb..87301d0bf5 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -2142,8 +2142,7 @@ and the action still plays. `Session::replay` plays a journal the same way. The `color` or `channel` it can't read. `window.panel` refuses every request in Presentation Mode, which hides every panel, and changes nothing. With -`toggle` it hides only a panel that can be seen, which is the panel the Window menu checks. With `toggle: false` a panel -that can be seen stays as it is, also in a flyout or a floating window. While Tab or Shift+Tab +`toggle` it hides only a panel that can be seen, which is the panel the Window menu checks. While Tab or Shift+Tab hides the dock, no panel is checked, and the panel shows again with the dock in its earlier place; the toolbar and the Control bar stay as they are. From 8eb3929762a5a2bceb1a4717805e7a1902e5cd45 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 19:49:12 -0800 Subject: [PATCH 20/26] Character Style Options: Insert Aki, Tsume and diacritic rows offer the Character panel's presets, as production's did Insert Aki Left and Right, Tsume and the Adjust Horizontal and Vertical Diacritic Position rows of Advanced Character Formats were plain text rows, without the presets menu the Character panel's fields have. Each is now a number field with that panel's presets (the craft-text AKI_PRESETS, TSUME_PRESETS and DIACRITIC_PRESETS), kept within the style's limits. The field still holds its text, so unset, automation and the limits applied at OK are unchanged. --- .../ui-egui/src/dialogs/char_style_options.rs | 56 ++++++++++++++++--- .../src/dialogs/char_style_options/tests.rs | 35 ++++++++++++ 2 files changed, 83 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/dialogs/char_style_options.rs b/crates/ui-egui/src/dialogs/char_style_options.rs index 9fcb532c33..c94169d659 100644 --- a/crates/ui-egui/src/dialogs/char_style_options.rs +++ b/crates/ui-egui/src/dialogs/char_style_options.rs @@ -4,9 +4,11 @@ //! Each field is unset (empty, absent, or a checkbox in its unset state) or set, and an unset field leaves //! its attribute out of the style. A field still as it opened keeps the style's stored value as it is. +use std::ops::RangeInclusive; use std::sync::Arc; use craft::behavior::Mixed; +use craft::text::ui::character::{AKI_PRESETS, DIACRITIC_PRESETS, TSUME_PRESETS}; use craft::ui::choice::Checkbox; use craft::ui::contract::{Bind, Entry, Outcome as _, Props as _, Show as _}; use craft::ui::dialog::{DialogResult, FieldRefusal}; @@ -14,7 +16,8 @@ use craft::ui::patterns::form_dialogs::{ DialogFields, FieldValue, HostedPropertiesDialog, Param, ParamKind, PropertiesDialog, PropertiesTab, PropertyRow, TabLayout, }; use craft::ui::pickers::Select; -use craft::ui::runtime::env::Label; +use craft::ui::runtime::env::{Env, Label}; +use craft::ui::text::{NumberField, NumberPick}; use serde_json::{Map, Value, json}; use vectorcraft_doc::setup::DocSetup; @@ -895,7 +898,39 @@ fn basic_rows() -> Vec { ]) } -// PLAN: the Aki, Tsume and Diacritic rows are plain text rows: `Param::text` has no preset menu to carry the Character panel's presets. +/// A number row over the text field `key` (empty for unset) whose menu offers `presets`, as the Character panel's field +/// of the same name does. A typed value stays within `range`; automation sets the field's text, as for a text row. +fn preset_number(key: &'static str, label: String, range: RangeInclusive, presets: &'static [f32]) -> Param { + let name = label.clone(); + Param::custom(key, label, move |ui, fields, _| { + let value = fields.text(key).and_then(|text| text.trim().parse::().ok()).filter(|n| n.is_finite()); + let units = Env::of(ui).units(); + let rows: Vec> = presets + .iter() + .map(|&p| { + let n = f64::from(p); + Entry::new(NumberPick::Number(n), units.number(n, 0..=2)) + }) + .collect(); + let out = NumberField::new(name.clone(), Bind::given(value)).range(range.clone()).presets(&rows).id_salt(key).show(ui); + if let Some(picked) = out.edit.value() { + let text = picked.map(|n| n.to_string()).unwrap_or_default(); + if fields.text(key) != Some(text.as_str()) { + fields.set(key, FieldValue::Text(text)); + } + } + out.edit.response.clone() + }) + // Set from outside: the field's text, as a text row takes it. + .on_set(|fields, key, value| match value { + Value::String(text) => { + fields.set(key, FieldValue::Text(text)); + Ok(()) + } + other => Err(FieldRefusal::Rejects(&other).message(key)), + }) +} + fn advanced_rows() -> Vec { let mut params: Vec = [ ("h_scale", tl!("Horizontal Scale"), "%"), @@ -904,15 +939,20 @@ fn advanced_rows() -> Vec { ("tcyUpDown", tl!("Tate-chu-yoko Up/Down"), "pt"), ("tcyLeftRight", tl!("Tate-chu-yoko Left/Right"), "pt"), ("rotation", tl!("Character Rotation"), "°"), - ("akiLeft", tl!("Insert Aki Left"), ""), - ("akiRight", tl!("Insert Aki Right"), ""), - ("tsume", tl!("Tsume"), "%"), - ("diacriticHorizontal", tl!("Adjust Horizontal Diacritic Position"), ""), - ("diacriticVertical", tl!("Adjust Vertical Diacritic Position"), ""), ] .into_iter() - .map(|(key, caption, unit)| text(key, if unit.is_empty() { caption.to_string() } else { format!("{caption} ({unit})") })) + .map(|(key, caption, unit)| text(key, format!("{caption} ({unit})"))) .collect(); + let aki = 0.0..=vectorcraft_doc::text::MAX_AKI; + let tsume = 0.0..=vectorcraft_doc::text::MAX_TSUME; + let diacritic = -vectorcraft_doc::text::MAX_DIACRITIC_POSITION..=vectorcraft_doc::text::MAX_DIACRITIC_POSITION; + params.extend([ + preset_number("akiLeft", tl!("Insert Aki Left").to_string(), aki.clone(), &AKI_PRESETS), + preset_number("akiRight", tl!("Insert Aki Right").to_string(), aki, &AKI_PRESETS), + preset_number("tsume", format!("{} (%)", tl!("Tsume")), tsume, &TSUME_PRESETS), + preset_number("diacriticHorizontal", tl!("Adjust Horizontal Diacritic Position").to_string(), diacritic.clone(), &DIACRITIC_PRESETS), + preset_number("diacriticVertical", tl!("Adjust Vertical Diacritic Position").to_string(), diacritic, &DIACRITIC_PRESETS), + ]); let languages: Vec<(&'static str, &'static str)> = vectorcraft_doc::setup::LANGUAGES.iter().map(|(name, _, _)| (*name, *name)).collect(); params.push(select("language", tl!("Language:"), &languages)); rows(params) diff --git a/crates/ui-egui/src/dialogs/char_style_options/tests.rs b/crates/ui-egui/src/dialogs/char_style_options/tests.rs index 79884992c4..a5af1854ec 100644 --- a/crates/ui-egui/src/dialogs/char_style_options/tests.rs +++ b/crates/ui-egui/src/dialogs/char_style_options/tests.rs @@ -547,6 +547,41 @@ fn tsume_field_shows_sets_resets_and_commits() { assert!(t.runs.iter().all(|r| r.style.tsume == 75.0)); } +/// The Insert Aki, Tsume and diacritic rows each have the Character panel's presets menu beside the field, and a +/// preset picked from it is the field's value and commits to the style, with each frame drawn once. +#[test] +fn aki_tsume_and_diacritic_rows_pick_from_the_character_panel_presets() { + use craft::ui::testing::Fixture; + let mut fx = Fixture::new(|ui| crate::dialogs::host::window_dialogs(ui.ctx()).with(|host| host.run(ui))); + fx.room(egui::vec2(900.0, 900.0)); + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.ui_ctx = Some(fx.ctx().clone()); + app.run("file.new", json!({"width": 300, "height": 200})).unwrap(); + styled(&mut app, json!({"size": 24.0}), "Text"); + open(&mut app, "Body"); + set::(&app, "tab", json!("advanced")); + fx.settle(); + + let presets_in_row = |fx: &Fixture, label: &str| { + let field = fx.by_label(label).unwrap_or_else(|| panic!("the {label} field")); + let tree = fx.tree(); + tree.keys().into_iter().filter(|key| tree.name_of(*key) == Some("Presets")).filter_map(|key| fx.target(key)).find(|chevron| { + chevron.rect.center().y > field.rect.top() && chevron.rect.center().y < field.rect.bottom() && chevron.rect.left() >= field.rect.left() + }) + }; + for label in ["Insert Aki Left", "Insert Aki Right", "Tsume (%)", "Adjust Horizontal Diacritic Position", "Adjust Vertical Diacritic Position"] { + assert!(presets_in_row(&fx, label).is_some(), "{label} has a presets menu"); + } + + let chevron = presets_in_row(&fx, "Insert Aki Left").unwrap(); + fx.click(&chevron).settle(); + let pick = fx.by_label("500").expect("the 500 preset"); + fx.click(&pick).settle(); + assert_eq!(fields::(&app)["akiLeft"], json!("500")); + assert!(ok::(&mut app)); + assert_eq!(app.session.doc().unwrap().doc.char_styles[0].attrs, attrs(json!({"size": 24.0, "akiLeft": 500.0}))); +} + /// The negated tags of the twenty stylistic sets: an explicit empty Stylistic Sets choice. fn no_sets() -> Vec { vectorcraft_text::EXTRA_FEATURES[..20].iter().map(|s| format!("-{s}")).collect() From e9c2f6cfd31a9d2342c85c54e87c44f6d2c8220e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 19:53:20 -0800 Subject: [PATCH 21/26] Recolor Artwork: with every color preserved, the Colors table shows its "No colors to recolor" note as its own empty-state text inside its body, instead of a line above five empty rows, as production did --- crates/ui-egui/src/dialogs/recolor.rs | 16 +++++++--------- crates/ui-egui/src/tests/recolor.rs | 13 +++++++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/dialogs/recolor.rs b/crates/ui-egui/src/dialogs/recolor.rs index fb8aea7c51..2c84010b1e 100644 --- a/crates/ui-egui/src/dialogs/recolor.rs +++ b/crates/ui-egui/src/dialogs/recolor.rs @@ -2094,9 +2094,6 @@ fn assign_tab( } }); } - if rows.is_empty() { - Text::new(tl!("No colors to recolor (preserved colors are left out).")).shade(Shade::Muted).show(ui); - } let columns = vec![ ColumnSpec::new( CURRENT, @@ -2124,10 +2121,12 @@ fn assign_tab( let source = keyed(&keys, |k| *k).with_text(|k| Cow::Owned(names.get(*k).cloned().unwrap_or_default())); let edits: RefCell> = RefCell::new(Vec::new()); let shown_rows: &[Value] = rows; - let out = Table::::new(tl!("Colors"), columns).min_rows(5).max_rows(8).selection(Bind::bound(&mut sel)).show_items( - ui, - &source, - &mut |key, icx| { + let out = Table::::new(tl!("Colors"), columns) + .min_rows(5) + .max_rows(8) + .empty(tl!("No colors to recolor (preserved colors are left out).")) + .selection(Bind::bound(&mut sel)) + .show_items(ui, &source, &mut |key, icx| { let i = *key; let edits = &edits; let row = shown_rows.get(i).cloned().unwrap_or_default(); @@ -2161,8 +2160,7 @@ fn assign_tab( edits.borrow_mut().push(RowEdit::Hex(i, *c)); } }) - }, - ); + }); let mut items = sel.items.clone(); items.sort_unstable(); items.dedup(); diff --git a/crates/ui-egui/src/tests/recolor.rs b/crates/ui-egui/src/tests/recolor.rs index 224bdc989c..6ab2abd049 100644 --- a/crates/ui-egui/src/tests/recolor.rs +++ b/crates/ui-egui/src/tests/recolor.rs @@ -677,6 +677,19 @@ fn the_preserve_checkboxes_open_as_they_were_last_confirmed() { assert_eq!(preserve(&r), [json!(false), json!(false), json!(true)], "Cancel keeps what OK left"); } +#[test] +fn with_every_color_preserved_the_colors_table_says_so_in_its_body() { + let mut app = app(); + art(&mut app, &["#ffffff", "#000000"]); + let mut r = assign(app, json!({})); + assert!(r.rows().is_empty(), "White and Black are preserved"); + let note = "No colors to recolor (preserved colors are left out)."; + let inside = |r: &Recolor| rect(r, "Colors").contains_rect(rect(r, note)); + assert!(inside(&r), "the note is drawn inside the Colors table, not above its empty rows"); + r.frame(); + assert!(inside(&r), "and stays there on the next frame"); +} + fn new_hsb(r: &Recolor) -> Vec<[f32; 3]> { field(r, "rows").as_array().unwrap().iter().map(|row| vectorcraft_engine::cmd::color_value(&row["to"]).unwrap().to_hsb()).collect() } From b9f6233c69d917a9f630fd1c17e6ea70d237605d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 20:19:58 -0800 Subject: [PATCH 22/26] Save for Web: a shift map over 256 entries is kept whole A `shifted` map with more than 256 entries is one the engine refuses, so the shift edit no longer drops its self-shifts and deleted colors. A shift that would leave more than 256 colors shifted, including a new target for a color that is already shifted, is refused with the limit error. --- .../src/dialogs/save_for_web/color_table.rs | 27 ++++++++++--------- .../src/dialogs/save_for_web/tests_table.rs | 16 +++++++++++ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/dialogs/save_for_web/color_table.rs b/crates/ui-egui/src/dialogs/save_for_web/color_table.rs index 39b03bc9d9..cbeedbe224 100644 --- a/crates/ui-egui/src/dialogs/save_for_web/color_table.rs +++ b/crates/ui-egui/src/dialogs/save_for_web/color_table.rs @@ -196,30 +196,33 @@ fn delete(table: &mut Value, picked: &[String], shown: &[[u8; 3]]) -> Result<(), } /// Shift the source colour `from` to `to`, wherever it is in the image; it is no longer -/// web-shifted. Shifting a colour to itself takes its shift away. A new source when 256 colours -/// are already shifted is refused with the engine's limit error, and nothing changes. Entries the +/// web-shifted. Shifting a colour to itself takes its shift away. A shift that would leave more +/// than 256 colours shifted is refused with the engine's limit error, and nothing changes. Entries the /// engine drops (a colour shifted to itself, a deleted colour) do not count, and a new shift writes /// the map without them. pub(crate) fn shift(table: &mut Value, from: [u8; 3], to: [u8; 3]) -> Result<(), String> { let (source, to) = (hex(from), hex(to)); let deleted: Vec<[u8; 3]> = list(table, "deleted").iter().filter_map(|c| parse(c)).collect(); let map = shifts(table); - // Entries are dropped only from a map the engine accepts (every key and value a colour, no two - // keys naming one colour); any other map is kept whole for the engine to refuse. + // Entries are dropped only from a map the engine accepts (at most 256 entries, every key and + // value a colour, no two keys naming one colour); any other map is kept whole for the engine to + // refuse. let mut keys: Vec<[u8; 3]> = Vec::new(); - let valid = map.iter().all(|(k, v)| match (parse(k), v.as_str().and_then(parse)) { - (Some(k), Some(_)) if !keys.contains(&k) => { - keys.push(k); - true - } - _ => false, - }); + let valid = map.len() <= webexport::MAX_TABLE + && map.iter().all(|(k, v)| match (parse(k), v.as_str().and_then(parse)) { + (Some(k), Some(_)) if !keys.contains(&k) => { + keys.push(k); + true + } + _ => false, + }); let live = |k: &str, v: &Value| { let (true, Some(key), Some(to)) = (valid, parse(k), v.as_str().and_then(parse)) else { return true }; to != key && !deleted.contains(&key) }; let count = map.iter().filter(|(k, v)| live(k, v)).count(); - if to != source && count >= webexport::MAX_TABLE && !map.iter().any(|(k, v)| live(k, v) && same(k, &source)) { + let held = usize::from(map.iter().any(|(k, v)| live(k, v) && same(k, &source))); + if to != source && count - held >= webexport::MAX_TABLE { return Err(webexport::too_many("shifted")); } unshift(table, &source); diff --git a/crates/ui-egui/src/dialogs/save_for_web/tests_table.rs b/crates/ui-egui/src/dialogs/save_for_web/tests_table.rs index 6dabd4c119..6f8d414185 100644 --- a/crates/ui-egui/src/dialogs/save_for_web/tests_table.rs +++ b/crates/ui-egui/src/dialogs/save_for_web/tests_table.rs @@ -148,6 +148,22 @@ fn a_shift_skips_entries_the_engine_drops() { } } +/// A map with more than 256 entries is one the engine refuses, so none of its entries are dropped: +/// with 257 colours shifted to themselves, a new shift and a new target for a shifted colour are +/// refused with the limit error and nothing changes. Taking a shift away still works. +#[test] +fn a_shift_keeps_a_map_over_the_limit_whole() { + let over: serde_json::Map = (0..257).map(|i| (format!("#{i:06x}"), json!(format!("#{i:06x}")))).collect(); + let mut t = json!({"shifted": over}); + let before = t.clone(); + let e = shift(&mut t, [0x12, 0x34, 0x56], A).unwrap_err(); + assert_eq!((e, &t), (webexport::too_many("shifted"), &before)); + let e = shift(&mut t, [0, 0, 5], [0x12, 0x34, 0x56]).unwrap_err(); + assert_eq!((e, &t), (webexport::too_many("shifted"), &before)); + shift(&mut t, [0, 0, 5], [0, 0, 5]).unwrap(); + assert_eq!(t["shifted"].as_object().map(|m| m.len()), Some(256)); +} + /// A key or list entry written another way (`#F00`, upper case, `blue`) still names its colour: /// a new shift replaces it, Unshift and the buttons take it out, the marks show it, and a /// spelling with alpha names no colour. From c1859a1f1e31f8977a586d6d7268cd7add81cb51 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 19:18:32 -0800 Subject: [PATCH 23/26] Undo: an anchor drag ends when a command renumbers its path A command run during a Direct Selection drag of anchors or segments, such as Add Anchor Point or Reverse Path Direction, can number the path's anchors anew. The drag kept its old anchor numbers and then moved a different point. When the command changes a path that holds the drag's selected anchors or segments in more than a move of the whole path, the drag now ends without a step of its own, and the command's edit stays. A command that only moves the path leaves the drag going on the same anchor. --- crates/engine/src/session/edit.rs | 41 ++++++++++++- .../engine/src/tests/interaction_commands.rs | 61 +++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/session/edit.rs b/crates/engine/src/session/edit.rs index a70850f44d..cc7af44898 100644 --- a/crates/engine/src/session/edit.rs +++ b/crates/engine/src/session/edit.rs @@ -342,7 +342,9 @@ impl Session { /// Drawing showed is applied to it again. The warning or the error of that preview goes to /// the command's result ([`Session::note_settled_warning`]); a preview that fails leaves the /// interaction with nothing to commit. An interaction whose document the command closed ends, - /// and a document the command left an interaction of its own on keeps that one. + /// and so does one with anchors or segments selected on a path the command changed in more + /// than a move. A document + /// the command left an interaction of its own on keeps that one. 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 }; // A selection command loaded the paints of the selection it made into the fill and stroke @@ -412,6 +414,13 @@ impl Session { } return; } + // The drag's anchors and segments are numbered in the paths it began on. When the command + // changed one of those paths in more than a move, the numbers can name other points, and + // the drag ends without a step. + if renumbered(&it.selection, &it.doc, &st.doc) { + self.clear_deferred_overlay_cache(); + return; + } let began = std::mem::replace(&mut it.doc, st.doc.clone()); // The drag acts on the objects it began with: a selection the command made (a paste, a // duplicate, Select All) does not change what the drag moves. @@ -773,6 +782,36 @@ fn drag_targets(params: &mut Value, began: &Document, doc: &Document) -> bool { !ids.is_empty() } +/// Whether a path with anchors or segments in `selection` is other in `doc` than in `began`, the +/// document a drag began from, in more than a move: its anchors added, removed, put in another +/// order (Reverse Path Direction) or reshaped, or a subpath opened or closed. A path the command +/// moved as a whole keeps its numbers. +fn renumbered(selection: &Selection, began: &Document, doc: &Document) -> bool { + fn path(d: &Document, id: vectorcraft_doc::NodeId) -> Option<&[vectorcraft_geom::SubPath]> { + d.node(id).and_then(|n| n.path_data()).map(|p| p.subpaths.as_slice()) + } + selection.anchors.keys().chain(selection.segments.keys()).any(|&id| match (path(began, id), path(doc, id)) { + (Some(was), Some(now)) => !moved_whole(was, now), + (was, now) => was.is_some() != now.is_some(), + }) +} + +/// Whether the subpaths `now` are the subpaths `was` moved by one offset: the same number of each, +/// each opened or closed as before, every anchor of the same kind, and every anchor and handle +/// offset alike. +fn moved_whole(was: &[vectorcraft_geom::SubPath], now: &[vectorcraft_geom::SubPath]) -> bool { + if was.len() != now.len() || was.iter().zip(now).any(|(a, b)| a.closed != b.closed || a.anchors.len() != b.anchors.len()) { + return false; + } + let mut pairs = was.iter().zip(now).flat_map(|(a, b)| a.anchors.iter().zip(b.anchors.iter())); + let Some((a0, b0)) = pairs.next() else { return true }; + let (dx, dy) = (b0.p.x - a0.p.x, b0.p.y - a0.p.y); + let alike = |a: vectorcraft_geom::Point, b: vectorcraft_geom::Point| { + (b.x - a.x - dx).abs() <= vectorcraft_geom::EPS && (b.y - a.y - dy).abs() <= vectorcraft_geom::EPS + }; + std::iter::once((a0, b0)).chain(pairs).all(|(a, b)| a.kind == b.kind && alike(a.p, b.p) && alike(a.h_in, b.h_in) && alike(a.h_out, b.h_out)) +} + /// The journal entries that select `selection` again in `doc` after `made`, the selection a /// command left with `layer` current and `rows` highlighted in the Layers panel ([`object_steps`]). /// When selecting the objects would make another layer current, `layer.setCurrent` makes `layer` diff --git a/crates/engine/src/tests/interaction_commands.rs b/crates/engine/src/tests/interaction_commands.rs index 1c24f26440..d0d12cce94 100644 --- a/crates/engine/src/tests/interaction_commands.rs +++ b/crates/engine/src/tests/interaction_commands.rs @@ -722,6 +722,67 @@ fn a_scale_rotate_or_pen_drag_of_an_object_a_command_deleted_ends_without_an_edi } } +/// A Direct Selection drag of an anchor, with a command during it that numbers the path's anchors +/// anew (Add Anchor Point before the dragged one, Reverse Path Direction): the command's edit +/// stays, the drag ends without an edit of its own and moves no other anchor of the path. +#[test] +fn an_anchor_drag_after_a_command_renumbers_its_anchors_moves_no_other_anchor() { + let commands = [("path.insertAnchor", json!({"segment": 0, "t": 0.5}), 1), ("path.reverse", json!({}), 0)]; + for ((id, params, added), real_time) in commands.iter().flat_map(|c| [(c, true), (c, false)]) { + let at = format!("{id}, real time {real_time}"); + let (mut s, target, _) = two_squares(real_time); + s.execute("select.none", &json!({})).unwrap(); + s.select_tool("directSelection", view()).unwrap(); + let points = |s: &Session| -> Vec<(f64, f64)> { + let doc = &s.doc().unwrap().doc; + let path = doc.node(target).and_then(|n| n.path_data()).expect("the square is a path"); + path.anchors().map(|(_, _, a)| (a.p.x, a.p.y)).collect() + }; + let before = points(&s); + let &(x, y) = before.last().expect("the square has anchors"); + let steps = s.doc().unwrap().history.undo.len(); + let mut params = params.clone(); + params["id"] = json!(target.0); + drag_with(&mut s, &[(x, y), (x + 10.0, y + 10.0), (x + 30.0, y + 20.0)], |s| { + s.execute(id, ¶ms).unwrap(); + }); + assert!(!s.in_interaction(), "{at}"); + let after = points(&s); + assert_eq!(after.len(), before.len() + added, "{at}: the command's edit stays"); + assert!(before.iter().all(|p| after.contains(p)), "{at}: no anchor of the square moved: {before:?} → {after:?}"); + assert_eq!(s.doc().unwrap().history.undo.len(), steps + 1, "{at}: only the command is a step"); + } +} + +/// A Direct Selection drag of an anchor, with a command during it that moves the path: the drag +/// goes on and moves the same anchor of the moved path. +#[test] +fn an_anchor_drag_after_a_command_moves_its_path_moves_the_same_anchor() { + for real_time in [true, false] { + let at = format!("real time {real_time}"); + let (mut s, target, _) = two_squares(real_time); + s.execute("select.none", &json!({})).unwrap(); + s.select_tool("directSelection", view()).unwrap(); + let points = |s: &Session| -> Vec<(f64, f64)> { + let doc = &s.doc().unwrap().doc; + let path = doc.node(target).and_then(|n| n.path_data()).expect("the square is a path"); + path.anchors().map(|(_, _, a)| (a.p.x, a.p.y)).collect() + }; + let before = points(&s); + let &(x, y) = before.last().expect("the square has anchors"); + let steps = s.doc().unwrap().history.undo.len(); + drag_with(&mut s, &[(x, y), (x + 10.0, y + 10.0), (x + 30.0, y + 20.0)], |s| { + s.execute("object.move", &json!({"ids": [target.0], "dx": 0, "dy": 50})).unwrap(); + }); + let after = points(&s); + let last = before.len() - 1; + let moved: Vec<(f64, f64)> = + before.iter().enumerate().map(|(i, &(px, py))| if i == last { (px + 30.0, py + 70.0) } else { (px, py + 50.0) }).collect(); + assert_eq!(after, moved, "{at}: the drag moves the same anchor of the moved square"); + assert_eq!(s.doc().unwrap().history.undo.len(), steps + 2, "{at}: the move and the drag are a step each"); + } +} + /// With the Live Paint Bucket's Selection tool (Cmd+drag), a fill chosen during the drag stays the /// new-art fill after the release and after Escape, though the drag puts back the bucket's colors /// it began with. From 461e758fe70c7f7917717aa8d49328f635ae397b Mon Sep 17 00:00:00 2001 From: BFlat Date: Wed, 25 Nov 2026 13:29:00 +0700 Subject: [PATCH 24/26] Look: Home, the dock frame and the panels' spacing as production 0.24.1 draws them (#9276) * Dock: rail_cards is now column_cards in craft-libs * Dock: pill panel tabs and rounded floating bodies, as production drew them * Root looks: neutral link labels, hover command highlight, strong choices, accent slider tracks, filled dialog buttons, spaced sections * Canvas: artboard edges black for the active artboard and grey for the others, as production drew them * Canvas: smart guide labels in their overlay's colour, as production drew them * Canvas: bleed in the error red and artboard marks in the grid grey, as production drew them * Document tabs: production's strip heights, regular and large * Floating window close test: aim at the title bar above the window's tab strip * Place the selection widgets over the canvas, so a frame runs its UI once SelectionWidgets was laid out in the canvas body's flow, which the layout check found changed in every frame the canvas drew: the frame was discarded and its whole UI ran a second time. It is placed over the canvas's rect, as the other canvas controls are. * Give nine trials the frames their behaviour needs now that a frame runs its UI once * Give the merge-press and corner-list trials what their behaviour needs now that a frame runs its UI once A merge the press frame applies changes the layout, so that frame runs again and its second pass already makes the held press: the check accepts the lent tool once the merge is no longer pending. The picked corner list fades out on the clock, which the trial now moves past before it checks the list is gone. * Pin craft-libs at 357f332549af53e1a273c2952c3e9c44157bef72 * Field labels in the normal ink, semibold document tabs, Stroke and Opacity without a colon, a plain Properties Rotate field, as production drew them * Only the shown pass of the canvas body starts the frame's panes, so a release over a floating window in the frame the pointer reached it drops the art * Pin craft-libs at 75efd247498d47e41604f418bceb2adaf0e3b329 * A collapsed panel column's icon groups stand apart by a hairline, as production drew them * Fill and Stroke chips: production's small square wells with their arrow, in the Properties panel and the Control bar * The dock's columns stand flush and square at production's widths: a 310-point panel column and a 38-point icon column, the panel tabs in the framework's plain look * The app bar's end shows Discord, a search icon and the workspace switcher, as production 0.24.1 does; tutorials and Arrange Documents stay in the Window menu * Home: StartScreen's Column layout as production lays it out: the centred welcome title and subtitle, New and Open, the recent files as rows, Learn, the presets as page cards under Quickly start a new file, and Community's links with Join our Discord as the call to action; the Home title is 26-point (typography.display). The recent-files trial finds rows by name and folder. Needs the framework's StartLayout::Column (craft-libs fix/vc-home) * Properties: the kind line heads the sections under it (QuietHeader::Heads), so the first draws no divider above it, as production's did * Link labels (Stroke, Opacity:) draw their underline inside the label (LinkLabelUnderline::Inside), under the text as production drew it; it was clipped away * Push buttons stand 24 points high (size.button), as production's flat buttons; fields stay 26 * Quiet headings (the kind line, Ellipse Properties:) stand a line of text high over their fields (QuietTitleRow::Text), as production's did * Layers rows: the thumbnail with a tight gap and 14 points of indent per level (ThumbRows::Tight): 26-point rows as production's * Layers: the Objects search field fills the filter bar up to its Filter button (ObjectsSearch::Fill), as production's did * Home: production's "New file" and "Open" words, 60 points of page margin above the title and a 36-point Join our Discord (size.page.margin, size.page.action); New Document's preset cards show blank paper on flat cards (PresetCardLook::Page), as production drew them. Needs craft-libs fix/vc-home 9cf00b80e or later * Control screenshots: frames keep coming until a capture is answered, not only until it is issued; its readback finishes in a later frame, so with nothing else repainting (the Color flyout open) a screenshot waited for the next wake, where production's capture kept painting * Icon buttons draw 16-point glyphs (size.icon.glyph_md) in their 26-point buttons, as production's did (60% of the button): Align, the Transform flips, More Options * craft-libs at next 461493afc: the panel spacing options, the menu Copy after Select All and Home's Column page options; pdf-deps follows * Files dropped on a floating panel window open as before: the dock now names the panel each drop landed on (craft-libs a2967e3cc), which the app does not use * The dock takes production 0.24.1's frame: block panel tabs on canvas strips with the column bars 14 points high, the tool column the only card with a square canvas strip on top, docks flush against the canvas with framed icon columns and square docked flyouts, the open panel's icon on the control surface; the status bar's rotation and artboard selects are filled * craft-libs at next 4bed21baa: VectorCraft's dock frame options (block panel tabs, stepped column cards, flush docks, ruled icon groups with production's grip bands, filled status selects); egui follows the framework to b15ffe9bf; pdf-deps follows * Color Wheel: the opacity row reads the target and color from the rows' pick #7642's opacity row used the target, color and color settings of the old panel function, which #9256 split into show_rows. It now reads them from the Pick show_rows gets, and leaves the gap to the stack, as the other rows do. --- Cargo.lock | 209 +++++++++--------- Cargo.toml | 96 ++++---- apps/vectorcraft-web/Cargo.toml | 2 +- crates/mcp/src/ui_catalog.rs | 2 +- crates/ui-egui/src/app.rs | 50 ++++- crates/ui-egui/src/app/control.rs | 5 +- crates/ui-egui/src/canvas/artboards.rs | 5 +- crates/ui-egui/src/canvas/drops.rs | 7 +- crates/ui-egui/src/canvas/home.rs | 15 +- crates/ui-egui/src/canvas/marks.rs | 18 +- crates/ui-egui/src/canvas/overlays.rs | 7 +- crates/ui-egui/src/canvas/panes/tests.rs | 29 --- .../ui-egui/src/canvas/selection_widgets.rs | 2 +- crates/ui-egui/src/canvas/tests.rs | 16 +- crates/ui-egui/src/chrome.rs | 72 +----- crates/ui-egui/src/chrome/status_bar.rs | 8 +- crates/ui-egui/src/chrome/tests.rs | 10 +- .../src/dialogs/tests_print_presets.rs | 2 + crates/ui-egui/src/doc_windows/tests.rs | 26 ++- crates/ui-egui/src/menus.rs | 1 - crates/ui-egui/src/menus/tree.rs | 10 +- crates/ui-egui/src/menus/ui_commands.rs | 2 +- crates/ui-egui/src/panel_docking.rs | 17 +- crates/ui-egui/src/panels.rs | 14 +- crates/ui-egui/src/panels/color_wheel.rs | 8 +- crates/ui-egui/src/panels/learn.rs | 6 +- crates/ui-egui/src/panels/learn/tests.rs | 16 +- .../panels/properties/appearance_section.rs | 6 +- .../panels/properties/transform_section.rs | 2 +- crates/ui-egui/src/panels/stroke.rs | 2 +- crates/ui-egui/src/panels/transform.rs | 23 +- .../ui-egui/src/shortcuts/held_tool/tests.rs | 2 + crates/ui-egui/src/shortcuts/tests.rs | 4 +- crates/ui-egui/src/tests/document_drag.rs | 3 +- crates/ui-egui/src/tests/home.rs | 8 +- crates/ui-egui/src/tests/lifecycle.rs | 21 ++ crates/ui-egui/src/tests/nativemenu.rs | 4 +- crates/ui-egui/src/tests/selectall.rs | 7 +- crates/ui-egui/src/tests/taskbar.rs | 2 + crates/ui-egui/src/theme.rs | 24 +- docs/mcp.md | 7 +- docs/target-app-parity.md | 4 +- docs/ui-parity.md | 2 +- xtask/src/pdf_deps.rs | 2 +- 44 files changed, 420 insertions(+), 358 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 193e5ed374..1b57f15652 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1134,7 +1134,7 @@ dependencies = [ [[package]] name = "craft" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-automation", "craft-behavior", @@ -1175,7 +1175,7 @@ dependencies = [ [[package]] name = "craft-affinity" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "crc32fast", "flate2", @@ -1186,7 +1186,7 @@ dependencies = [ [[package]] name = "craft-appkit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "block2 0.6.2", "objc2-app-kit 0.3.2", @@ -1196,7 +1196,7 @@ dependencies = [ [[package]] name = "craft-atomic" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "rustix 1.1.6", ] @@ -1204,7 +1204,7 @@ dependencies = [ [[package]] name = "craft-automation" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "base64 0.23.1", "craft-behavior", @@ -1229,7 +1229,7 @@ dependencies = [ [[package]] name = "craft-behavior" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "accesskit", "bitflags 2.13.2", @@ -1247,7 +1247,7 @@ dependencies = [ [[package]] name = "craft-browse" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-docpath", @@ -1265,7 +1265,7 @@ dependencies = [ [[package]] name = "craft-cdr" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "crc32fast", "flate2", @@ -1274,7 +1274,7 @@ dependencies = [ [[package]] name = "craft-cloud-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "egui", ] @@ -1282,7 +1282,7 @@ dependencies = [ [[package]] name = "craft-cms" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "md-5", "rayon", @@ -1291,12 +1291,12 @@ dependencies = [ [[package]] name = "craft-codepage" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" [[package]] name = "craft-color-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-cms", @@ -1316,7 +1316,7 @@ dependencies = [ [[package]] name = "craft-control" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "getrandom 0.3.4", "serde", @@ -1326,7 +1326,7 @@ dependencies = [ [[package]] name = "craft-dds" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "rayon", ] @@ -1334,7 +1334,7 @@ dependencies = [ [[package]] name = "craft-dialogs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "block2 0.6.2", "craft-atomic", @@ -1359,7 +1359,7 @@ dependencies = [ [[package]] name = "craft-docpath" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "serde", ] @@ -1367,7 +1367,7 @@ dependencies = [ [[package]] name = "craft-draw" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-color-ui", @@ -1386,7 +1386,7 @@ dependencies = [ [[package]] name = "craft-dxf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-codepage", "encoding_rs", @@ -1398,12 +1398,12 @@ dependencies = [ [[package]] name = "craft-eps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" [[package]] name = "craft-font-catalog" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "fontique", "harfrust 0.13.3", @@ -1418,7 +1418,7 @@ dependencies = [ [[package]] name = "craft-font-manager" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-font-catalog", @@ -1431,13 +1431,13 @@ dependencies = [ "egui", "log", "serde", - "skrifa 0.44.0", + "skrifa 0.47.0", ] [[package]] name = "craft-font-store" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "cap-primitives", "craft-atomic", @@ -1453,17 +1453,18 @@ dependencies = [ "thiserror 2.0.21", "toml", "ureq", + "wuff", ] [[package]] name = "craft-fonts-build" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" [[package]] name = "craft-gif" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "gif", ] @@ -1471,7 +1472,7 @@ dependencies = [ [[package]] name = "craft-gzip" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "flate2", ] @@ -1479,7 +1480,7 @@ dependencies = [ [[package]] name = "craft-host" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "bitflags 2.13.2", "craft-i18n", @@ -1492,7 +1493,7 @@ dependencies = [ [[package]] name = "craft-i18n" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "chrono", "fixed_decimal", @@ -1520,7 +1521,7 @@ dependencies = [ [[package]] name = "craft-image-codecs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-dds", "craft-jpeg", @@ -1547,7 +1548,7 @@ dependencies = [ [[package]] name = "craft-imaging" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-color-ui", @@ -1565,7 +1566,7 @@ dependencies = [ [[package]] name = "craft-jpeg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "thiserror 2.0.21", ] @@ -1573,7 +1574,7 @@ dependencies = [ [[package]] name = "craft-jxl" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "brotli-decompressor 5.0.3", "jixel", @@ -1584,7 +1585,7 @@ dependencies = [ [[package]] name = "craft-keymap" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-host", "craft-i18n", @@ -1599,7 +1600,7 @@ dependencies = [ [[package]] name = "craft-layers" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-i18n", @@ -1613,7 +1614,7 @@ dependencies = [ [[package]] name = "craft-menu" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-host", @@ -1631,7 +1632,7 @@ dependencies = [ [[package]] name = "craft-metadata" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "brotli-decompressor 6.3.2", "chrono", @@ -1643,7 +1644,7 @@ dependencies = [ [[package]] name = "craft-metafile" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "encoding_rs", "image", @@ -1654,7 +1655,7 @@ dependencies = [ [[package]] name = "craft-mime" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "chrono", "craft-codepage", @@ -1664,7 +1665,7 @@ dependencies = [ [[package]] name = "craft-pages" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-keymap", @@ -1680,7 +1681,7 @@ dependencies = [ [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "hayro-interpret", "hayro-syntax", @@ -1692,7 +1693,7 @@ dependencies = [ [[package]] name = "craft-platform" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "async-channel", "async-io", @@ -1723,7 +1724,7 @@ dependencies = [ [[package]] name = "craft-plotter" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "kurbo 0.13.1", "thiserror 2.0.21", @@ -1732,7 +1733,7 @@ dependencies = [ [[package]] name = "craft-print" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-host", @@ -1756,7 +1757,7 @@ dependencies = [ [[package]] name = "craft-proof" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "log", "miniz_oxide 0.9.1", @@ -1767,7 +1768,7 @@ dependencies = [ [[package]] name = "craft-ps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-eps", "flate2", @@ -1781,7 +1782,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "encoding_rs", "flate2", @@ -1792,7 +1793,7 @@ dependencies = [ [[package]] name = "craft-quit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "dispatch2", "egui", @@ -1805,7 +1806,7 @@ dependencies = [ [[package]] name = "craft-review" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "base64 0.23.1", "craft-behavior", @@ -1824,7 +1825,7 @@ dependencies = [ [[package]] name = "craft-settings" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-atomic", "craft-host", @@ -1841,7 +1842,7 @@ dependencies = [ [[package]] name = "craft-stream-codecs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "fax", "hayro-ccitt", @@ -1852,7 +1853,7 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-image-codecs", "craft-xml", @@ -1873,7 +1874,7 @@ dependencies = [ [[package]] name = "craft-table" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-keymap", @@ -1885,7 +1886,7 @@ dependencies = [ [[package]] name = "craft-text" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-font-manager", @@ -1910,7 +1911,7 @@ dependencies = [ [[package]] name = "craft-theme" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "bitflags 2.13.2", "craft-tracked", @@ -1925,7 +1926,7 @@ dependencies = [ [[package]] name = "craft-theme-store" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-atomic", "craft-behavior", @@ -1940,7 +1941,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "serde", "thiserror 2.0.21", @@ -1950,7 +1951,7 @@ dependencies = [ [[package]] name = "craft-time" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "serde", "thiserror 2.0.21", @@ -1959,7 +1960,7 @@ dependencies = [ [[package]] name = "craft-timeline" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-keymap", @@ -1974,12 +1975,12 @@ dependencies = [ [[package]] name = "craft-tracked" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-cloud-ui", "craft-ui-canvas", @@ -1993,7 +1994,7 @@ dependencies = [ [[package]] name = "craft-ui-canvas" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-i18n", @@ -2009,7 +2010,7 @@ dependencies = [ [[package]] name = "craft-ui-contract" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "accesskit", "craft-behavior", @@ -2047,7 +2048,7 @@ dependencies = [ [[package]] name = "craft-ui-macros" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2058,7 +2059,7 @@ dependencies = [ [[package]] name = "craft-ui-panels" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-host", @@ -2076,7 +2077,7 @@ dependencies = [ [[package]] name = "craft-ui-patterns" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-host", @@ -2097,7 +2098,7 @@ dependencies = [ [[package]] name = "craft-ui-shell" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-host", @@ -2118,7 +2119,7 @@ dependencies = [ [[package]] name = "craft-ui-widgets" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-behavior", "craft-host", @@ -2137,7 +2138,7 @@ dependencies = [ [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "chrono", "craft-host", @@ -2166,7 +2167,7 @@ dependencies = [ [[package]] name = "craft-vectorcraft-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "flate2", "serde", @@ -2177,7 +2178,7 @@ dependencies = [ [[package]] name = "craft-wayland" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "raw-window-handle", "wayland-backend", @@ -2187,7 +2188,7 @@ dependencies = [ [[package]] name = "craft-web-api" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "js-sys", "serde_json", @@ -2198,7 +2199,7 @@ dependencies = [ [[package]] name = "craft-win32" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "winsafe", ] @@ -2206,7 +2207,7 @@ dependencies = [ [[package]] name = "craft-window" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "craft-appkit", "craft-atomic", @@ -2238,7 +2239,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "quick-xml 0.41.0", "serde", @@ -2400,7 +2401,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -2526,7 +2527,7 @@ checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" [[package]] name = "ecolor" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "bytemuck", "emath", @@ -2535,7 +2536,7 @@ dependencies = [ [[package]] name = "eframe" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "ahash", "bytemuck", @@ -2570,7 +2571,7 @@ dependencies = [ [[package]] name = "egui" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "accesskit", "ahash", @@ -2589,7 +2590,7 @@ dependencies = [ [[package]] name = "egui-wgpu" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "ahash", "bytemuck", @@ -2608,7 +2609,7 @@ dependencies = [ [[package]] name = "egui-winit" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "accesskit_winit", "arboard", @@ -2633,7 +2634,7 @@ dependencies = [ [[package]] name = "egui_extras" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "ahash", "egui", @@ -2647,7 +2648,7 @@ dependencies = [ [[package]] name = "egui_glow" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "bytemuck", "egui", @@ -2660,7 +2661,7 @@ dependencies = [ [[package]] name = "egui_kittest" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "dify", "eframe", @@ -2686,7 +2687,7 @@ checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be" [[package]] name = "emath" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "bytemuck", ] @@ -2767,7 +2768,7 @@ dependencies = [ [[package]] name = "epaint" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "ahash", "bytemuck", @@ -2793,7 +2794,7 @@ dependencies = [ [[package]] name = "epaint_default_fonts" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" [[package]] name = "equivalent" @@ -3083,7 +3084,7 @@ checksum = "94e7099f6313ecacbe1256e8ff9d617b75d1bcb16a6fddef94866d225a01a14a" dependencies = [ "io-lifetimes 2.0.4", "rustix 1.1.6", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -3506,7 +3507,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a" [[package]] name = "hayro-cmap" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "brotli", "hayro-postscript", @@ -3515,7 +3516,7 @@ dependencies = [ [[package]] name = "hayro-interpret" version = "0.7.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "bitflags 2.13.2", "hayro-cmap", @@ -3533,7 +3534,7 @@ dependencies = [ [[package]] name = "hayro-jbig2" version = "0.3.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "fearless_simd", "hayro-ccitt", @@ -3551,12 +3552,12 @@ dependencies = [ [[package]] name = "hayro-postscript" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" [[package]] name = "hayro-syntax" version = "0.7.2" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "flate2", "hayro-ccitt", @@ -4116,7 +4117,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20fd6de4ccfcc187e38bc21cfa543cb5a302cb86a8b114eb7f0bf0dc9f8ac00f" dependencies = [ "io-lifetimes 3.0.1", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -4487,7 +4488,7 @@ dependencies = [ [[package]] name = "krilla" version = "0.8.2" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "base64 0.22.1", "bumpalo", @@ -4644,7 +4645,7 @@ checksum = "d4a5ff6bcca6c4867b1c4fd4ef63e4db7436ef363e0ad7531d1558856bae64f4" [[package]] name = "linesweeper" version = "0.5.0" -source = "git+https://github.com/storytold/craft-libs?rev=a4b6d3b6ca04a65d5972339b808d1049a14c7167#a4b6d3b6ca04a65d5972339b808d1049a14c7167" +source = "git+https://github.com/storytold/craft-libs?rev=4bed21baaa41d2b47bef90879c04df521f6f6043#4bed21baaa41d2b47bef90879c04df521f6f6043" dependencies = [ "arrayvec", "kurbo 0.13.1", @@ -9717,7 +9718,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f3fd376f71958b862e7afb20cfe5a22830e1963462f3a17f49d82a6c1d1f42d" dependencies = [ "bitflags 2.13.2", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -9772,6 +9773,16 @@ dependencies = [ "either", ] +[[package]] +name = "wuff" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6a992b57b3d1ee972b2e3fd9225e44793104d49818836dd812d5459187712dd" +dependencies = [ + "brotli-decompressor 6.3.2", + "bytes", +] + [[package]] name = "x11-dl" version = "2.21.0" @@ -10280,14 +10291,14 @@ dependencies = [ [[patch.unused]] name = "egui_demo_lib" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" [[patch.unused]] name = "egui_inspection" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" [[patch.unused]] name = "egui_system_font_provider" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" diff --git a/Cargo.toml b/Cargo.toml index c03d9a7146..15f14067e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,44 +11,44 @@ rust-version = "1.95" repository = "https://github.com/storytold/vectorcraft" [workspace.dependencies] -craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167", default-features = false, features = ["interpret", "write"] } -craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -craft-proof = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } +craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043", default-features = false, features = ["interpret", "write"] } +craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +craft-proof = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } # The `.vectorcraft` envelope: its members, version, embedded images and the data after the JSON. -craft-vectorcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -craft-gzip = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } +craft-vectorcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +craft-gzip = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } # Native Affinity documents (craft-libs#914). -craft-affinity = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } +craft-affinity = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } # Bounded CDR (v1-v27) and CMX (32-bit) reader (craft-libs#778). -craft-cdr = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } +craft-cdr = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } # SVG parsing, limits, SVGZ and writer (craft-libs#778). -craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167", features = ["tree"] } -craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } +craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043", features = ["tree"] } +craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } # EPS container, previews, ASCII85 and DSC comments (craft-libs#778). -craft-eps = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } +craft-eps = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } # DXF tags, reader and writer (craft-libs#778, #926, #927). -craft-plotter = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -craft-dxf = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } +craft-plotter = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +craft-dxf = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } # WMF, EMF and EMF+ reader (craft-libs#778). -craft-metafile = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -craft-ps = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167", default-features = false, features = ["read", "write"] } -craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -craft-stream-codecs = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -craft-codepage = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } +craft-metafile = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +craft-ps = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043", default-features = false, features = ["read", "write"] } +craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +craft-stream-codecs = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +craft-codepage = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } # The framework facade (`craft::ui`, `craft::settings`, `craft::platform`, ...). No default features: each crate names # the members it imports. -craft = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } +craft = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } # Below the egui layer, so not through the facade: the colour harmony rules and their settings (craft-color-ui # without its `ui` feature), the colour type they work in, and the craft-fonts tables the text crate's build writes. -craft-color-ui = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -craft-theme = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -craft-fonts-build = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } +craft-color-ui = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +craft-theme = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +craft-fonts-build = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } # internal vectorcraft-geom = { path = "crates/geom" } vectorcraft-color = { path = "crates/color" } @@ -191,25 +191,25 @@ lto = "thin" codegen-units = 1 [patch.crates-io] -hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -krilla = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167" } -ecolor = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } -emath = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } -epaint = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } -epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } -egui = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } -egui-winit = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } -egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } -egui_glow = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } -egui_extras = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } -egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } -egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } -eframe = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } -egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } -egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "f5025284445ea19c35f746d96fc0b75468b3f560" } +hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +krilla = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043" } +ecolor = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +emath = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +epaint = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui-winit = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui_glow = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui_extras = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +eframe = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457d84ee4975110bfda6797c44dc" } diff --git a/apps/vectorcraft-web/Cargo.toml b/apps/vectorcraft-web/Cargo.toml index 70709d274d..ce5110f8ac 100644 --- a/apps/vectorcraft-web/Cargo.toml +++ b/apps/vectorcraft-web/Cargo.toml @@ -27,7 +27,7 @@ log = { workspace = true } # `wgpu` pulls egui-wgpu's defaults: WebGPU plus the WebGL2 fallback. eframe = { workspace = true, features = ["default_fonts", "wgpu", "accesskit"] } # The page command API (storytold/craft-libs#413): the request plumbing behind window.vectorcraft. -craft-web-api = { git = "https://github.com/storytold/craft-libs", rev = "a4b6d3b6ca04a65d5972339b808d1049a14c7167", version = "0.1.0" } +craft-web-api = { git = "https://github.com/storytold/craft-libs", rev = "4bed21baaa41d2b47bef90879c04df521f6f6043", version = "0.1.0" } wasm-bindgen = "0.2" serde_json = { workspace = true } diff --git a/crates/mcp/src/ui_catalog.rs b/crates/mcp/src/ui_catalog.rs index 3822e71ed0..18d0ebc247 100644 --- a/crates/mcp/src/ui_catalog.rs +++ b/crates/mcp/src/ui_catalog.rs @@ -789,7 +789,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[ "window.learn", "Learn", "", - "{show?: bool} show (true), hide (false) or toggle (omitted or null) the Learn panel, as Window › Learn and the app bar's Explore tutorials button do; any other value is an error and changes nothing; returns whether the panel shows", + "{show?: bool} show (true), hide (false) or toggle (omitted or null) the Learn panel, as Window › Learn does; any other value is an error and changes nothing; returns whether the panel shows", ), ( "learn.list", diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index fdf92146d2..b290892bb1 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -1,17 +1,25 @@ use craft::automation::ControlChannel; use craft::host::{AppInfo, Host, Wake}; +use craft::layers::ui::filter::ObjectsSearch; use craft::platform::clipboard::{Clipboard, ClipboardProbe, EventClipboard}; use craft::platform::clock::monotonic_ms; use craft::theme::variant::Tone; use craft::ui::buttons::{ActiveLook, PushButtonLook}; -use craft::ui::contract::{Bind, GlyphColon}; +use craft::ui::choice::ChoiceLook; +use craft::ui::contract::{Bind, CaptionInk, GlyphColon, LinkLabelInk, LinkLabelUnderline, QuietHeader, SectionRhythm}; +use craft::ui::docking::IconGroupSeparator; +use craft::ui::list::{CommandHighlight, ThumbRows}; use craft::ui::menu::MenuTitlePad; +use craft::ui::patterns::form_dialogs::PresetCardLook; use craft::ui::runtime::env::{RootEnv, Scale, ScrubDrags, WindowKey}; use craft::ui::runtime::frame::{FrameInput, FrameOutput}; use craft::ui::runtime::toast::{self, Toast}; use craft::ui::runtime::windows::WindowHost; +use craft::ui::sections::{DialogButtonLook, QuietTitleRow}; use craft::ui::shell::embed::CloseDecision; use craft::ui::shell::{AppShell, CanvasPanel, Slot}; +use craft::ui::style::TrackFill; +use craft::ui::tabs::DocumentTabLook; use craft::ui::text::{NumberLook, NumberPrecision}; use vectorcraft_engine::cmd::clipboard::PASTE_ORDER; use vectorcraft_engine::cmd::toast::Level; @@ -519,11 +527,13 @@ impl VectorcraftApp { pub(crate) fn canvas_area(&mut self, ui: &mut egui::Ui) { let opening = !self.opening.pending.is_empty(); let presenting = self.ui.presenting(); + let large_tabs = self.session.prefs.large_tabs; // The tab strip and the document are two closures of one panel: they take the app in // turn, and a borrow that fails (a closure re-entered) skips its part. let app = std::cell::RefCell::new(self); CanvasPanel::new() .opening(opening) + .large_tabs(large_tabs) .tabs(|ui, _cx| { if !presenting && let Ok(mut app) = app.try_borrow_mut() { chrome::doc_tabs(&mut app, ui); @@ -533,7 +543,10 @@ impl VectorcraftApp { let Ok(mut app) = app.try_borrow_mut() else { return }; let app: &mut VectorcraftApp = &mut app; app.canvas.windows.area = Some(ui.available_rect_before_wrap()); - app.canvas.windows.last_noted = std::mem::take(&mut app.canvas.windows.noted); + // Only the shown pass starts the frame's panes: a measuring run before it would drop the last frame's. + if !craft::ui::runtime::measure::active(ui.ctx()) { + app.canvas.windows.last_noted = std::mem::take(&mut app.canvas.windows.noted); + } let floats = crate::doc_windows::current_floats(app); // The current window's body is in its floating window, drawn after this pane: the pane's drop catcher // waits for it ([`crate::doc_windows::show`]). @@ -683,8 +696,41 @@ pub(crate) fn root_env(prefs: &vectorcraft_engine::Prefs, native_ppp: f32) -> Ro // A glyph that stands for a word caption ("X", "W") takes a form's colon as production drew it ("X:"); "#" and // the colour channel letters stay bare. root.values.set(GlyphColon::Form); + // A field's label that opens its options ("Opacity:", "Stroke") reads in the normal ink, underlined, as production + // drew it. + root.values.set(LinkLabelInk::Neutral); + // Its underline stands inside the label's rect, under the text, as production drew it. + root.values.set(LinkLabelUnderline::Inside); + // Other field labels ("X:", "Angle:", "Opacity") read in the normal ink of the values beside them, as production + // drew them. + root.values.set(CaptionInk::Normal); + // Menu rows, open menu bar titles and the command palette's active row show production's hover highlight. + root.values.set(CommandHighlight::Hover); + // Check boxes, radio buttons and switches that are on take the strong accent with a white mark, sliders fill their + // track to the value in the accent, and a dialog's Cancel is a filled button beside its accent answer. + root.values.set(ChoiceLook::Strong); + root.values.set(TrackFill::Accent); + root.values.set(DialogButtonLook::Filled); + // Sections stand apart with production's room around their dividers. + root.values.set(SectionRhythm::Spaced); + // The Properties kind line ("Ellipse") heads the sections under it, so the first draws no divider above it, as + // production's did. + root.values.set(QuietHeader::Heads); + // Quiet headings (the kind line, "Ellipse Properties:") stand a line of text high over their fields, as + // production's did. + root.values.set(QuietTitleRow::Text); + // Layers rows stand as production's: the thumbnail with a tight gap, 14 points of indent per level. + root.values.set(ThumbRows::Tight); + // The Layers Objects search field fills the filter bar up to its Filter button, as production's did. + root.values.set(ObjectsSearch::Fill); // The menu bar's titles stand as close as production's, which share the line with the bar's other controls. root.values.set(MenuTitlePad::Control); + // Document tabs show their title and its `*` in the label's semibold face, as production drew them. + root.values.set(DocumentTabLook::Semibold); + // A collapsed panel column's icon groups stand apart by a hairline, as production drew them. + root.values.set(IconGroupSeparator::Rule); + // New Document's preset cards show blank paper on a flat card, as production drew them. + root.values.set(PresetCardLook::Page); // A bare Tab on the canvas, or with nothing focused, toggles the panels (`window.dock`) instead of moving focus. root.tab_toggles_chrome = true; // Escape in a text field gives up its focus, reverting any typing, so the next keys are the window's. diff --git a/crates/ui-egui/src/app/control.rs b/crates/ui-egui/src/app/control.rs index 717f605120..69f1ac7b32 100644 --- a/crates/ui-egui/src/app/control.rs +++ b/crates/ui-egui/src/app/control.rs @@ -75,8 +75,9 @@ impl VectorcraftApp { } } // A capture is issued only after passes settle it, and an idle window runs none; a hidden - // one runs only this logic unless asked to paint. - if self.channel.as_ref().is_some_and(|channel| channel.captures.any_unissued()) { + // one runs only this logic unless asked to paint. Its readback finishes only in a later frame, + // so frames keep coming until it is answered, as production's did. + if self.channel.as_ref().is_some_and(|channel| channel.captures.any_pending()) { if self.viewport_hidden(ctx) { host.paint_while_hidden(); } diff --git a/crates/ui-egui/src/canvas/artboards.rs b/crates/ui-egui/src/canvas/artboards.rs index 4313aa7b88..e493bbc561 100644 --- a/crates/ui-egui/src/canvas/artboards.rs +++ b/crates/ui-egui/src/canvas/artboards.rs @@ -1,5 +1,5 @@ use craft::behavior::{CanvasView, EditEvent}; -use craft::ui::canvas::{PageBorder, PageFrame, Pasteboard, PasteboardColor, PasteboardOutput}; +use craft::ui::canvas::{ArtboardEdge, PageBorder, PageFrame, Pasteboard, PasteboardColor, PasteboardOutput}; use craft::ui::contract::{Rename, Show as _}; use craft::ui::primitives::Checker; use craft::ui::style::DataColor; @@ -98,7 +98,8 @@ pub(super) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, space: &CanvasSp let outline = view.outline; let list = frames(app, st, view, outline); // The pasteboard's colour is the canvas's (`Canvas::pasteboard`). - let out = Pasteboard::new("Artboards", &list).border(border(outline)).shows_outside().show_at(ui, space.view.rect); + let out = + Pasteboard::new("Artboards", &list).border(border(outline)).artboard_edge(ArtboardEdge::Plain).shows_outside().show_at(ui, space.view.rect); match kind { BodyKind::Live => apply(app, &out), BodyKind::Pane => None, diff --git a/crates/ui-egui/src/canvas/drops.rs b/crates/ui-egui/src/canvas/drops.rs index 60cbe32993..7a8b606305 100644 --- a/crates/ui-egui/src/canvas/drops.rs +++ b/crates/ui-egui/src/canvas/drops.rs @@ -195,8 +195,11 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut Ui, win: Win, kind: BodyKi later.push((win, rect, ui.layer_id())); return; } - // A pane outside Tile (a floating window's, the main window's while the current window floats). - app.canvas.windows.noted.push((win, rect)); + // A pane outside Tile (a floating window's, the main window's while the current window floats), as shown: a + // measuring run's area is not where it draws. + if !craft::ui::runtime::measure::active(ui.ctx()) { + app.canvas.windows.noted.push((win, rect)); + } } let view = match kind { BodyKind::Live => app.canvas_view(), diff --git a/crates/ui-egui/src/canvas/home.rs b/crates/ui-egui/src/canvas/home.rs index 6ee333f604..e2dfa19c73 100644 --- a/crates/ui-egui/src/canvas/home.rs +++ b/crates/ui-egui/src/canvas/home.rs @@ -3,7 +3,7 @@ use craft::ui::buttons::Button; use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _}; use craft::ui::display::Text; use craft::ui::layout_components::Row; -use craft::ui::shell::{RecentFile, StartAction, StartLink, StartScreen, Template}; +use craft::ui::shell::{RecentFile, StartAction, StartLayout, StartLink, StartScreen, Template}; use super::{Ui, VectorcraftApp, json}; @@ -25,25 +25,32 @@ pub(super) fn home(app: &mut VectorcraftApp, ui: &mut Ui, rect: egui::Rect) { let templates: Vec