DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge #618: Paste vector art from Illustrator, VectorCraft or Figma as editable paths
aiongg09e8118b21ae
diff --cc ROADMAP.mdindex 71a034174,36c334e2d..b687addb0--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -128,40 -129,7 +128,41 @@@ list) · [roadmap.md](docs/roadmap.md)Newest first.+ - **2026-10-12** · Vector art copied in Illustrator, VectorCraft, Figma or Inkscape pastes as editable paths, as InDesign pastes Illustrator art: the SVG those apps put on the clipboard becomes paths with their fills, strokes (weight, caps, joins, dashes) and opacity, groups stay groups and text comes in as outlines, centred in the view (`edit.pasteSvg`, `ui.paste`). Edit › Paste reads the system clipboard when nothing was copied in DesignCraft. No readiness percentage change.+- **2026-10-12** · Pages panel: double-clicking a parent shows that parent and selects only its row; parent rows show rendered thumbnails. Commands name parents by id, full name, or a prefix only one parent has; an unknown or ambiguous name is an error instead of clearing the page's parent (#624). No readiness percentage change.+- **2026-10-12** · With the Type tool, dragging a table's column or row border resizes it (the double-arrow cursor shows over a border): later columns and rows move along, Shift keeps the table size, and Shift on the right or bottom edge scales every column or row. A dragged row becomes At Least; one undo step per drag, Esc cancels; works in rotated frames and turned spreads. Scripts use `table.resizeBorder`. No readiness percentage change.+- **2026-10-12** · The Tools panel's Fill/Stroke keys work: D (default fill and stroke), X (fill or stroke in front), Shift+X (swap per object, tints included) and / (Apply None), as `color.*` commands; swap and default are one undo step (`object.swapFillStroke`, `object.defaultFillStroke`); the Color panel follows the proxy's fill/stroke choice. No readiness percentage change.+- **2026-10-12** · With a placed graphic selected (Direct Selection), the Transform values act on the graphic inside its frame, as in InDesign: a tilted frame's image can be straightened to 0°. No readiness percentage change.+- **2026-10-11** · Font menu laid out like InDesign's: filters (classification, favourites,+ recently added), families opening to their styles, the selected text as the sample in three+ sizes, Recently Used fonts, Show Similar Fonts and each font's format.+- **2026-10-12** · The Effects panel shows the level its settings apply to ("Group: Color Dodge 100%") and, as in InDesign, Isolate Blending and Knockout Group for a selected group. No readiness percentage change.+- **2026-10-12** · Edit › Step and Repeat has its InDesign dialog: Repeat (Count, or Rows and Columns with Create as a grid), Offset (Vertical, Horizontal, in ruler units) and Preview, which shows the copies while the dialog is open; Cancel takes them away and OK makes them as one undo step. No readiness percentage change.+- **2026-10-12** · Load Styles: the Paragraph Styles and Character Styles panels load styles from another DesignCraft document or an IDML file, with the styles, swatches and lists they name; a dialog picks the styles and what happens to one the document defines differently (`style.load`). No readiness percentage change.+- **2026-10-12** · On screen, blend modes blend with the objects below and not with the paper, as in InDesign and in PDF export: a Color Dodge or Screen object over blank paper shows as it is. No readiness percentage change.+- **2026-10-12** · Text threads by hand: click a selected text frame's in or out port to load+ the text cursor, then click a frame to thread it, click empty space for a column-wide frame or+ drag one (it snaps like frame drawing); Shift-click autoflows, Alt-click stays loaded on the+ frame just added; click the linked frame or double-click a port to break the thread.+ `text.thread`, `text.unthread`, `text.removeFromThread` with undo; locked frames and layers+ refuse threads. The alpha gate now waits only on the Primary Text Frame page fixes (#165). No+ readiness percentage change.+- **2026-10-12** · Properties › Transform shows rotation, shear and X/Y scale, and Rotate 90° and Flip Horizontal/Vertical buttons, as InDesign's does. No readiness percentage change.+- **2026-10-12** · Underlines and strikethroughs are drawn as one bar per stretch of text on screen, as in PDF export: a bar per letter left faint seams between the letters. No readiness percentage change.+- **2026-10-12** · The section marker character shows its section's marker text on document pages (nothing when the section has none) instead of the word "Section", which stays on parent pages; editing the marker recomposes (#556). No readiness percentage change.+- **2026-10-12** · IDML import keeps a font family name exactly as written, trailing spaces included, and font lookup falls back to the name without surrounding spaces; `FontStyle="Nothing"` leaves the style to the paragraph (#558). No readiness percentage change.+- **2026-10-12** · Clipping paths saved with images in IDML (Detect Edges, Alpha Channel, Photoshop Path, User-Modified Path, inverted or not) clip the image on screen and in PDF and survive IDML export; `object.clippingPathOptions` reports, inverts or removes one (#450). No readiness percentage change.+- **2026-10-12** · Anchored objects with text wrap push text aside: other stories' text under them and the lines of their own story after the anchor's line (#557). No readiness percentage change.+- **2026-10-12** · Hyphenation Zone applies to the Single-line Composer only, as in InDesign. With the default Paragraph Composer, ragged text hyphenates where InDesign does (aper-natem), giving the same line breaks. No readiness percentage change.+- **2026-10-12** · Text frame auto-size: Height Only, Width Only, Height and Width (also keeping proportions) frames grow and shrink to fit their text after edits and IDML import, around their reference point, with minimum sizes and No Line Breaks, in the same undo step (#180). No readiness percentage change.+- **2026-10-12** · Text Frame Options › Balance Columns (`object.textFrameOptions {balanceColumns}`, IDML `VerticalBalanceColumns`) evens out the columns of the frame a story ends in, from its last column break on; frames the text runs on from fill normally (#609). No readiness percentage change.+- **2026-10-12** · macOS Dock Quit uses the same unsaved-document prompts as window and menu Quit. Repeated requests keep the current answers; Cancel retains every tab and unsaved recovery checkpoint, and completed Save/Don't Save answers exit through the ordinary event loop. No readiness percentage change.+- **2026-10-12** · Orderly native exit writes the latest recovery state after finalizing current quit approvals; incomplete or stale plans keep their documents, and Undo to the saved state clears stale recovery. Unavailable or failed recovery is reported. Cancelable macOS Dock Quit remains open (#544). No readiness percentage change.+- **2026-10-12** · Windows: dragging the window across monitors with different display scales keeps its size instead of growing until it crashes (winit pinned to its 0.30.x backport of the fix). The GPU surface may be as large as the adapter's largest texture (16384 px on DirectX 12, Vulkan and Metal hardware) instead of 8192, and a wgpu error is logged instead of closing the app. No readiness percentage change.+- **2026-10-12** · Recovered documents keep a checkpoint until saved, closed or reverted, including a second crash before autosave. Restarted document IDs and explicit recovery folders preserve other snapshots; failed republishing retains the original. No readiness percentage change.+- **2026-10-12** · Book numbering and style updates prepare every chapter before saving. Only closed native chapters are changed; imported IDML remains a read-only style/PDF source. If a later disk write fails, the error names the completed chapters; the batch is not a whole-book transaction. No readiness percentage change.+- **2026-10-12** · Desktop write callbacks and CLI raster exports use the atomic writer too; open readers retain the original bytes, while private Unix modes and symlink targets survive replacement. Permanent tests cover both actual callers. No readiness percentage change.+- **2026-10-12** · Save As, library edits and book collection edits persist prospective values before changing live state; failed writes preserve the document and existing collections. Save a Copy rebases data-source paths for its destination without changing the open document. No readiness percentage change.- **2026-10-12** · Window close and application/menu Quit ask about unsaved documents; later Cancel keeps every tab open, including earlier Don't Save choices. Approvals are rechecked after edits. Cancelable macOS Dock Quit remains open (#544). No readiness percentage change.- **2026-10-12** · Each running app keeps recovery data in its own locked folder; current folder and lock ownership are checked before writes and cleanup. Failed isolation disables recovery with a warning instead of sharing document IDs. No readiness percentage change.- **2026-10-12** · Native engine saves and exports replace files atomically; failed writes retain the original, private staging preserves Unix permissions, and valid long filenames work. Desktop Services and CLI raster exports remain separate follow-ups. No readiness percentage change.diff --cc crates/engine/src/cmd/mod.rsindex 0149bfbf9,8b7454be5..0a7fb5d1d--- a/crates/engine/src/cmd/mod.rs+++ b/crates/engine/src/cmd/mod.rs@@@ -315,6 -301,6 +317,7 @@@ pub fn file_from(b: &[u8]) -> Result<de}pub(crate) use datamerge::sync_placeholders;pub(crate) use file::load_document_fonts;-pub use file::{base64_decode, base64_encode, from_bytes, to_bytes};+pub use file::{base64_decode, base64_encode, from_bytes, is_document, to_bytes, with_document_extension};+pub use layout::chapter_numbering;+ pub use paste_svg::is_svg_markup;pub(crate) use place_text::autoflow as place_text_autoflow;diff --cc crates/ui-egui/src/canvas.rsindex 3997f37ed,396710b4a..1151e3400--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@@ -2679,285 -1793,57 +2679,328 @@@ mod tests(s.horizontal_units, s.vertical_units)}+ fn zoom_app(tool: &str) -> DesignApp {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({})).unwrap();+ app.select_tool(tool);+ app.ui.rulers = false;+ app+ }++ fn canvas_frame(app: &mut DesignApp, ctx: &egui::Context, m: egui::Modifiers, mut events: Vec<egui::Event>) -> egui::CursorIcon {+ events.insert(0, egui::Event::ModifiersChanged(m));+ let mut output = ctx.run_ui(+ egui::RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0))), events, ..Default::default() },+ |ui| {+ app.logic(ui.ctx());+ // Fonts installed by logic become available at the start of the next frame,+ // just as in the full application UI.+ if app.fonts_ready {+ show(app, ui);+ }+ },+ );+ output.textures_delta.clear();+ output.platform_output.cursor_icon+ }++ /// The cursor icon the canvas sets for `c` on this platform (bitmap and painted cursors+ /// report their own icon).+ fn shown(c: Cursor) -> egui::CursorIcon {+ crate::cursors::show(&egui::Context::default(), &mut crate::cursors::Images::default(), c, Pos2::ZERO)+ }++ fn space_key(pressed: bool, modifiers: egui::Modifiers) -> egui::Event {+ egui::Event::Key { key: egui::Key::Space, physical_key: None, pressed, repeat: false, modifiers }+ }++ fn press(pos: Pos2, pressed: bool, modifiers: egui::Modifiers) -> egui::Event {+ egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers }+ }++ fn hover(app: &mut DesignApp, ctx: &egui::Context, p: Pos2) {+ for _ in 0..3 {+ canvas_frame(app, ctx, egui::Modifiers::NONE, vec![egui::Event::PointerMoved(p)]);+ }+ }++ const CMD: egui::Modifiers = egui::Modifiers { command: true, mac_cmd: true, ..egui::Modifiers::NONE };++ #[test]+ fn spring_zoom_click_is_anchored_view_only_and_release_restores_previous_tool() {+ for tool in ["rectangleFrame", "directSelection", "type", "hand", "zoom"] {+ let mut app = zoom_app(tool);+ if tool == "rectangleFrame" {+ let frame = app.run("frame.create", json!({"rect":[36,36,300,200],"content":"text","text":"Hello"})).unwrap();+ app.run("text.select", json!({"story":frame["story"],"anchor":5})).unwrap();+ }+ let ctx = egui::Context::default();+ let p = pos2(300.0, 250.0);+ hover(&mut app, &ctx, p);+ let before = *app.view().unwrap();+ let doc = app.session.doc().unwrap().doc.clone();+ let selection = app.session.doc().unwrap().selection.clone();+ let history = app.run("document.history", json!({})).unwrap();+ let cursor = canvas_frame(&mut app, &ctx, CMD, vec![space_key(true, CMD)]);+ assert_eq!(cursor, shown(Cursor::ZoomIn), "{tool}");+ canvas_frame(&mut app, &ctx, CMD, vec![press(p, true, CMD)]);+ canvas_frame(&mut app, &ctx, CMD, vec![press(p, false, CMD)]);+ let after = *app.view().unwrap();+ assert_eq!(after.zoom, before.zoom * 2.0, "{tool}");+ let anchor = Xf::new(app.canvas_rect.unwrap(), &before).to_canvas(p);+ assert!((Xf::new(app.canvas_rect.unwrap(), &after).to_canvas(p) - anchor).hypot() < 1e-9);+ let cursor = canvas_frame(&mut app, &ctx, egui::Modifiers::NONE, vec![space_key(false, egui::Modifiers::NONE)]);+ assert_eq!(app.session.tool_id(), tool);+ let expected = app.session.cursor(anchor, Mods::default(), app.view_info());+ assert_eq!(cursor, shown(expected), "{tool}");+ assert!(std::sync::Arc::ptr_eq(&doc, &app.session.doc().unwrap().doc));+ assert_eq!(selection, app.session.doc().unwrap().selection);+ assert_eq!(history, app.run("document.history", json!({})).unwrap());+ }+ }++ #[test]+ fn spring_zoom_alt_clicks_out_and_modifier_release_switches_back_to_hand() {+ let mut app = zoom_app("rectangleFrame");+ let ctx = egui::Context::default();+ let p = pos2(300.0, 250.0);+ hover(&mut app, &ctx, p);+ let z = app.view().unwrap().zoom;+ let alt = egui::Modifiers { alt: true, ..CMD };+ assert_eq!(canvas_frame(&mut app, &ctx, CMD, vec![space_key(true, CMD)]), shown(Cursor::ZoomIn));+ assert_eq!(canvas_frame(&mut app, &ctx, alt, vec![]), shown(Cursor::ZoomOut));+ canvas_frame(&mut app, &ctx, alt, vec![press(p, true, alt)]);+ canvas_frame(&mut app, &ctx, alt, vec![press(p, false, alt)]);+ assert_eq!(app.view().unwrap().zoom, z * 0.5);+ assert_eq!(canvas_frame(&mut app, &ctx, egui::Modifiers::NONE, vec![]), shown(Cursor::Hand));+ let before = *app.view().unwrap();+ canvas_frame(&mut app, &ctx, egui::Modifiers::NONE, vec![press(p, true, egui::Modifiers::NONE)]);+ canvas_frame(&mut app, &ctx, egui::Modifiers::NONE, vec![egui::Event::PointerMoved(p + vec2(80.0, 0.0))]);+ canvas_frame(&mut app, &ctx, egui::Modifiers::NONE, vec![press(p + vec2(80.0, 0.0), false, egui::Modifiers::NONE)]);+ assert_eq!(app.view().unwrap().zoom, before.zoom);+ assert!(app.view().unwrap().origin.x < before.origin.x);+ assert_eq!(app.session.tool_id(), "rectangleFrame");+ }++ #[test]+ fn spring_zoom_scrubs_and_owns_pointer_release_after_shortcut_release() {+ let mut app = zoom_app("rectangleFrame");+ let ctx = egui::Context::default();+ let p = pos2(300.0, 250.0);+ hover(&mut app, &ctx, p);+ let z = app.view().unwrap().zoom;+ let doc = app.session.doc().unwrap().doc.clone();+ // Ctrl is the platform command modifier on Windows/Linux, using the same input path.+ let cmd = egui::Modifiers { command: true, ctrl: true, ..egui::Modifiers::NONE };+ canvas_frame(&mut app, &ctx, cmd, vec![space_key(true, cmd), press(p, true, cmd)]);+ let end = p + vec2(150.0, 0.0);+ canvas_frame(&mut app, &ctx, cmd, vec![egui::Event::PointerMoved(end)]);+ assert!((app.view().unwrap().zoom - z * std::f64::consts::E).abs() < 1e-9);+ let scrubbed = app.view().unwrap().zoom;+ assert_eq!(canvas_frame(&mut app, &ctx, egui::Modifiers::NONE, vec![space_key(false, egui::Modifiers::NONE)]), shown(Cursor::Crosshair));+ canvas_frame(&mut app, &ctx, egui::Modifiers::NONE, vec![press(end, false, egui::Modifiers::NONE)]);+ assert_eq!(app.view().unwrap().zoom, scrubbed, "no extra click zoom at the end of a scrub");+ assert!(std::sync::Arc::ptr_eq(&doc, &app.session.doc().unwrap().doc));+ // The original tool still draws after the temporary gesture.+ canvas_frame(&mut app, &ctx, egui::Modifiers::NONE, vec![press(p, true, egui::Modifiers::NONE)]);+ canvas_frame(&mut app, &ctx, egui::Modifiers::NONE, vec![egui::Event::PointerMoved(p + vec2(50.0, 50.0))]);+ canvas_frame(&mut app, &ctx, egui::Modifiers::NONE, vec![press(p + vec2(50.0, 50.0), false, egui::Modifiers::NONE)]);+ assert!(!std::sync::Arc::ptr_eq(&doc, &app.session.doc().unwrap().doc));+ assert_eq!(app.session.tool_id(), "rectangleFrame");+ }++ #[test]+ fn spring_zoom_is_suppressed_while_typing_in_a_text_frame() {+ let mut app = zoom_app("type");+ let frame = app.run("frame.create", json!({"rect":[36,36,300,200],"content":"text","text":"Hello"})).unwrap();+ app.run("text.select", json!({"story":frame["story"],"anchor":5})).unwrap();+ assert!(app.session.wants_text());+ let ctx = egui::Context::default();+ let p = pos2(300.0, 250.0);+ hover(&mut app, &ctx, p);+ let before = *app.view().unwrap();+ let alt = egui::Modifiers { alt: true, ..CMD };+ for m in [CMD, alt] {+ app.run("text.select", json!({"story":frame["story"],"anchor":5})).unwrap();+ assert!(app.session.wants_text());+ assert!(!matches!(canvas_frame(&mut app, &ctx, m, vec![space_key(true, m)]), egui::CursorIcon::ZoomIn | egui::CursorIcon::ZoomOut));+ canvas_frame(&mut app, &ctx, m, vec![press(p, true, m)]);+ canvas_frame(&mut app, &ctx, m, vec![press(p, false, m)]);+ assert_eq!(app.view().unwrap().zoom, before.zoom);+ assert_eq!(app.view().unwrap().origin, before.origin);+ canvas_frame(&mut app, &ctx, egui::Modifiers::NONE, vec![space_key(false, egui::Modifiers::NONE)]);+ }+ }++ #[test]+ fn spring_zoom_is_suppressed_while_a_text_field_has_focus() {+ let mut app = zoom_app("rectangleFrame");+ let ctx = egui::Context::default();+ let mut text = String::new();+ let p = pos2(300.0, 250.0);+ hover(&mut app, &ctx, p);+ let before = *app.view().unwrap();+ for m in [egui::Modifiers::NONE, CMD, egui::Modifiers { alt: true, ..CMD }] {+ let mut output = ctx.run_ui(+ egui::RawInput {+ screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0))),+ events: vec![egui::Event::ModifiersChanged(m), space_key(true, m), egui::Event::Text("x".into()), egui::Event::PointerMoved(p)],+ ..Default::default()+ },+ |ui| {+ ui.text_edit_singleline(&mut text).request_focus();+ show(&mut app, ui);+ },+ );+ output.textures_delta.clear();+ assert!(ctx.text_edit_focused());+ assert!(!matches!(output.platform_output.cursor_icon, egui::CursorIcon::ZoomIn | egui::CursorIcon::ZoomOut | egui::CursorIcon::Grab));+ assert_eq!(app.view().unwrap().zoom, before.zoom);+ assert_eq!(app.session.tool_id(), "rectangleFrame");+ }+ assert!(!text.is_empty(), "typing still reaches the field");+ }++ #[test]+ fn spring_zoom_does_not_interrupt_an_existing_tool_drag() {+ let mut app = zoom_app("rectangleFrame");+ let ctx = egui::Context::default();+ let p = pos2(300.0, 250.0);+ hover(&mut app, &ctx, p);+ let before = *app.view().unwrap();+ let doc = app.session.doc().unwrap().doc.clone();+ canvas_frame(&mut app, &ctx, egui::Modifiers::NONE, vec![press(p, true, egui::Modifiers::NONE)]);+ let end = p + vec2(100.0, 100.0);+ canvas_frame(&mut app, &ctx, CMD, vec![space_key(true, CMD), egui::Event::PointerMoved(end)]);+ canvas_frame(&mut app, &ctx, CMD, vec![press(end, false, CMD)]);+ assert_eq!(app.view().unwrap().zoom, before.zoom);+ assert_eq!(app.view().unwrap().origin, before.origin);+ assert!(!std::sync::Arc::ptr_eq(&doc, &app.session.doc().unwrap().doc));+ }++ #[test]+ fn spring_zoom_does_not_zoom_on_the_rulers() {+ let mut app = zoom_app("rectangleFrame");+ app.ui.rulers = true;+ let ctx = egui::Context::default();+ hover(&mut app, &ctx, pos2(300.0, 250.0));+ let rect = app.canvas_rect.unwrap();+ let p = pos2(rect.min.x - RULER / 2.0, rect.center().y);+ hover(&mut app, &ctx, p);+ let before = *app.view().unwrap();+ canvas_frame(&mut app, &ctx, CMD, vec![space_key(true, CMD)]);+ canvas_frame(&mut app, &ctx, CMD, vec![press(p, true, CMD)]);+ canvas_frame(&mut app, &ctx, CMD, vec![press(p, false, CMD)]);+ assert_eq!(app.view().unwrap().zoom, before.zoom);+ assert_eq!(app.view().unwrap().origin, before.origin);+ }++ #[test]+ fn parent_guides_on_a_page_are_not_picked_there() {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({})).unwrap();+ // 100 pt into A's right page, which page 1 (a right page at x = 0) shows.+ let parent_guide = json!({"spread": {"kind": "parent", "index": 0}, "page": 1, "orientation": "vertical", "position": 712});+ app.run("guide.add", parent_guide).unwrap();+ let mut h = harness(app);+ let at = |app: &DesignApp| {+ let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap());+ let layout = CanvasLayout::new(&app.session.active().unwrap().doc, false);+ let slot = layout.slots.iter().find(|s| s.spread == SpreadRef::Doc(0)).unwrap();+ guide_at(app, &xf, xf.to_screen(slot.xf * Point::new(100.0, 300.0)))+ };+ assert_eq!(at(h.state()), None, "the parent's guide is edited on the parent");+ h.state_mut().run("guide.add", json!({"orientation": "vertical", "position": 100})).unwrap();+ h.run_steps(2);+ assert!(matches!(at(h.state()), Some((SpreadRef::Doc(0), 0, 0, _))), "the page's own guide is");+ }++ #[test]+ fn mouse_double_clicking_a_frame_handle_fits_with_one_undo_step() {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({})).unwrap();+ let id = designcraft_doc::ItemId(+ app.run("frame.create", json!({"rect": [100, 100, 400, 300], "content": "text", "text": "Fit this text"})).unwrap()["id"]+ .as_u64()+ .unwrap(),+ );+ app.run("selection.set", json!({"ids": [id.0]})).unwrap();+ let original = app.session.doc().unwrap().doc.item(id).unwrap().bounds();+ // 60 frames a second: the default 0.25 s step puts two clicks past egui's double-click delay.+ let mut h = Harness::builder().with_size(vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state(+ |ui, app: &mut DesignApp| {+ let ctx = ui.ctx().clone();+ app.logic(&ctx);+ app.ui(ui);+ },+ app,+ );+ h.run_steps(4);+ let app = h.state();+ let st = app.session.doc().unwrap();+ let layout = CanvasLayout::new(&st.doc, false);+ let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap());+ let p = xf.to_screen(layout.xf(SpreadRef::Doc(0)) * Point::new(original.x1, original.y1));+ h.hover_at(p);+ h.step();+ // Separate frames model the actual mouse, including egui's release-time double click.+ for _ in 0..2 {+ for pressed in [true, false] {+ h.event(egui::Event::PointerButton { pos: p, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() });+ h.step();+ }+ }+ h.run_steps(2);+ let fitted = h.state().session.doc().unwrap().doc.item(id).unwrap().bounds();+ assert!(fitted.width() < original.width() && fitted.height() < original.height(), "{fitted:?}");+ assert_eq!(h.state().session.tool_id(), "selection");+ h.state_mut().run("edit.undo", json!({})).unwrap();+ assert_eq!(h.state().session.doc().unwrap().doc.item(id).unwrap().bounds(), original);+ }++ const ART: &str = r##"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 50" width="100pt" height="50pt"><path d="M0,0 C30,0 70,50 100,50" fill="none" stroke="#000" stroke-width="2"/></svg>"##;++ #[test]+ fn pasting_svg_from_another_app_places_editable_paths_in_the_middle_of_the_view() {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({})).unwrap();+ let mut h = harness(app);++ h.run_steps(2);+ let undo = h.state().session.doc().unwrap().history.undo.len();+ h.event(egui::Event::Paste(ART.into()));+ h.run_steps(2);+ let app = h.state();+ let st = app.session.doc().unwrap();+ assert_eq!(st.history.undo.len(), undo + 1, "one undo step");+ let id = *st.selection.items.first().expect("the pasted path is selected");+ let it = st.doc.item(id).unwrap();+ assert_eq!(it.shape, designcraft_doc::Shape::Path);+ assert_eq!(it.path.subpaths[0].anchors.len(), 2);+ assert!((it.stroke.weight - 2.0).abs() < 1e-9);- // Centred where the view's centre falls on the spread.- let rect = app.canvas_rect.unwrap();- let xf = Xf::new(rect, app.view().unwrap());- let (_, centre) = CanvasLayout::new(&st.doc, false).spread_at(xf.to_canvas(rect.center())).unwrap();++ // Centred where text from another app would go: the middle of the view.++ let (_, centre) = view_centre(app).unwrap();+ assert!((it.bounds().center() - centre).hypot() < 0.01, "{:?} vs {centre:?}", it.bounds());- // Plain text pasted with no text being edited changes nothing.- let before = st.doc.clone();- h.event(egui::Event::Paste("just words".into()));- h.run_steps(2);- assert!(std::sync::Arc::ptr_eq(&before, &h.state().session.doc().unwrap().doc));+ }++ #[test]- fn edit_paste_with_nothing_copied_here_asks_for_the_system_clipboard() {- let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());++ fn edit_paste_from_the_menu_pastes_svg_on_the_system_clipboard_as_paths() {++ let services = crate::Services { clipboard_text: Some(Box::new(|| Some(ART.to_string()))), ..Default::default() };++ let mut app = DesignApp::new(designcraft_engine::Session::new(), services);++ app.native_menu = true;+ app.run("file.new", json!({})).unwrap();- assert!(!crate::menus::enabled(&app, "edit.paste"), "nothing copied in DesignCraft");- assert!(crate::menus::menu_enabled(&app, "edit.paste"), "the system clipboard may hold art");+ crate::menus::activate(&mut app, "edit.paste", &Value::Null);- assert!(app.request_system_paste);- let ctx = egui::Context::default();- let mut out = ctx.run_ui(egui::RawInput::default(), |ui| app.logic(ui.ctx()));- out.textures_delta.clear();- assert!(out.viewport_output[&egui::ViewportId::ROOT].commands.contains(&egui::ViewportCommand::RequestPaste));- assert!(!app.request_system_paste);- // With objects copied here, Edit › Paste pastes them as before.- let r = app.run("frame.create", json!({"rect": [10, 10, 50, 50]})).unwrap();- app.run("selection.set", json!({"ids": [r["id"]]})).unwrap();- app.run("edit.copy", json!({})).unwrap();++ let st = app.session.doc().unwrap();++ let id = *st.selection.items.first().expect("the pasted path is selected");++ assert_eq!(st.doc.item(id).unwrap().shape, designcraft_doc::Shape::Path);++ assert!(st.selection.text.is_none(), "paths, not a text frame of markup");++ // With an insertion point, the markup is text like any other.++ let story = app.run("frame.create", json!({"rect": [10, 10, 300, 300], "content": "text"})).unwrap()["story"].clone();++ app.run("text.select", json!({"story": story, "anchor": 0, "focus": 0})).unwrap();++ let items = app.session.doc().unwrap().doc.spreads[0].items.len();+ crate::menus::activate(&mut app, "edit.paste", &Value::Null);- assert!(!app.request_system_paste);++ assert_eq!(app.session.doc().unwrap().doc.spreads[0].items.len(), items, "no paths added");+ }+#[test]fn right_clicking_a_ruler_sets_that_rulers_units() {let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());diff --cc crates/ui-egui/src/lib.rsindex 146f0bbd7,927d5da89..d34934843--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@@ -693,60 -609,10 +693,72 @@@ impl DesignAppif let Some(r) = menus::run_ui(self, id, ¶ms) {return r;}+ // Only user-initiated runs touch the system clipboard, never the control channel's.+ let system_clipboard = !self.in_control;+ let mut params = if system_clipboard { self.with_system_clipboard(id, params) } else { params };++ // Vector art copied in another app (Illustrator, VectorCraft, Figma) is SVG markup on the++ // system clipboard: with no insertion point it pastes as editable paths where text would go.++ let typing = self.session.active().is_some_and(|d| d.selection.text.is_some());++ let id = match params.as_object_mut() {++ Some(o) if id == "edit.paste" && !typing && o.get("text").and_then(Value::as_str).is_some_and(designcraft_engine::cmd::is_svg_markup) => {++ if let Some(svg) = o.remove("text") {++ o.insert("svg".into(), svg);++ }++ "edit.pasteSvg"++ }++ _ => id,++ };+ // Copied objects paste on the spread in view.- if matches!(id, "edit.paste" | "edit.pasteInPlace")++ if matches!(id, "edit.paste" | "edit.pasteInPlace" | "edit.pasteSvg")+ && let Some(spread) = canvas::current_spread(self)+ && let Some(p) = params.as_object_mut()+ {+ p.entry("spread").or_insert(json!(spread));+ }let r = self.session.execute(id, ¶ms).map_err(|e| e.to_string());self.after_engine();- if let Err(e) = &r {- self.status(e.clone());+ match &r {+ Err(e) => self.status(e.clone()),+ // Copied text goes to the system clipboard too, whichever way Copy was chosen.+ Ok(v) if system_clipboard && matches!(id, "edit.copy" | "edit.cut") => {+ let text = match v.get("text").and_then(Value::as_str) {+ Some(t) => {+ self.object_clip_text = None;+ Some(t.to_string())+ }+ None if !self.native_menu => {+ self.object_clip_text = Some(self.copied_objects_text());+ self.object_clip_text.clone()+ }+ None => {+ self.object_clip_text = self.services.clipboard_text.as_mut().and_then(|f| f());+ None+ }+ };+ if let (Some(t), Some(ctx)) = (text, &self.egui_ctx) {+ ctx.copy_text(t);+ ctx.request_repaint();+ }+ }+ Ok(_) => {}+ }+ if r.is_ok() && matches!(id, "file.open" | "file.openIdml" | "file.openBytes") {+ if self.ui.dialog.as_ref().is_some_and(|d| d.id == "findFont") {+ self.ui.dialog = None;+ }+ match self.session.execute("font.list", &json!({})) {+ Ok(fonts) if fonts.as_array().is_some_and(|fonts| fonts.iter().any(|f| f["missing"] == true || f["styleMissing"] == true)) => {+ self.ui.dialog = Some(dialogs::Dialog::new("findFont", json!({"_fonts": fonts, "onOpen": true})));+ }+ Err(e) => self.status(e.to_string()),+ _ => {}+ }+ }+ if r.is_ok()+ && matches!(id, "font.replace" | "edit.undo" | "edit.redo")+ && let Some(dialog) = self.ui.dialog.as_mut().filter(|d| d.id == "findFont")+ {+ dialog.fields.remove("_fonts");}r}diff --cc docs/control-protocol.mdindex 249d1025e,506984fd6..cbaf6860a--- a/docs/control-protocol.md+++ b/docs/control-protocol.md@@@ -38,11 -37,11 +38,12 @@@ so only enable it while you use it. Tra| `ui.inspect` | — | Tool, UI state, view (zoom/origin), canvas rect, perf || `ui.menu.list` / `ui.tool.list` | — | Menu tree / Tools panel groups || `ui.tool.select` | `{tool}` | Select a tool (`selection`, `type`, `rectangleFrame`, …) |-| `ui.pointer` | `{events:[{kind: down\|drag\|up\|move\|doubleclick, x, y, space?: "screen"\|"canvas"}], mods?}` | Drive the active tool through the same code path as the mouse |+| `ui.pointer` | `{events:[{kind: down\|drag\|up\|move\|doubleclick, x, y, space?: "screen"\|"canvas", clicks?}], mods?}` | Drive the active tool through the same code path as the mouse; `clicks` on a `down` is the press count (3 = triple click); returns the selection, the tool and its cursor at the last event (e.g. `LoadedText`, `ThreadLink`, `Unthread`) || `ui.key` / `ui.text` | `{key, shift?, alt?, cmd?}` / `{text}` | Synthetic keyboard input (typing into a text frame) |+| `ui.ime` | `{preedit?, active?: [start, end], commit?}` | Input method events as the system IME sends them: marked text (shown in place, `active` is the clause being converted, in characters) and the committed text (typed as one `text.insert`) |+ | `ui.paste` | `{text}` | What Ctrl/Cmd+V delivers from the system clipboard: text into the text being edited, or SVG markup (vector art copied in Illustrator, VectorCraft or Figma) as editable paths in the middle of the view || `ui.move` / `ui.click` / `ui.drag` | screen points, `button?: left\|right\|middle` | Real egui pointer input — reaches every widget, menu and panel |-| `ui.set` | `{brightness?, panel?, rulers?, guides?, frameEdges?, baselineGrid?, textThreads?, screenMode?, zoom?, page?, fit?}` | UI state |+| `ui.set` | `{brightness?, panel?, rulers?, guides?, frameEdges?, baselineGrid?, documentGrid?, textThreads?, screenMode?, zoom?, page?, fit?}` | UI state || `ui.dialog.open` | `{id, fields?}` | Open a dialog by id (e.g. `paragraphStyleOptions` or `characterStyleOptions` with `{name, section}`, or `{new: true}` for a new style) || `ui.dialog.set` / `ui.dialog.confirm` / `ui.dialog.cancel` | `{field, value}` | Fill and confirm the open dialog || `ui.resize`, `ui.focus` | | Window control |