Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge origin/main into codex/document-setup-dialog

moppeeer12a41f69dbba
diff --cc ROADMAP.md
index 7af62345c,d60a6bf49..ed41691c0
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@@ -153,11 -438,16 +438,18 @@@ Newest first
- **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-11** · Properties gains InDesign's Pathfinder section (Add, Subtract, Intersect, Exclude Overlap, Minus Back) with several objects selected; section titles and icon buttons have accessible names. No readiness percentage change.
- **2026-10-12** · The Eyedropper samples a placed image: clicking the photo with text (or objects) selected fills them with the image's colour under the pointer, as an unnamed colour (`color.sample`), as in InDesign. Images on locked layers can be sampled. No readiness percentage change.
+- **2026-10-11** · Document Setup laid out like InDesign's: Page Size, Margins (new: every
+ page's, `layout.documentSetup {margins}`), Bleed and Slug with links, Adjust Layout.
+ - **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** · 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** · A gradient feather on a group fades the group as one, on screen and in PDF. Before, the screen ignored it, and PDF masked the group with a box of zero size because a group has no path of its own. No readiness percentage change.
+ - **2026-10-12** · In a CMYK transparency blend space (print documents), blend modes blend in CMYK on screen as in InDesign. Color Dodge with 100% K text turns coloured areas under it white and leaves the paper alone, where RGB blending changed almost nothing. PDF export already did this. No readiness percentage change.
+ - **2026-10-11** · Moving a sheared and rotated text frame no longer leaves trails of text behind: canvas repaints cover the frame's whole text box, not just its outline. No readiness percentage change.
- **2026-10-12** · Words in capitals hyphenate like capitalized words (FERRUM COM-MODI), as in InDesign; Hyphenate Capitalized Words off keeps them whole. No readiness percentage change.
+ - **2026-10-12** · Load Swatches refuses an `.ase` file with more than 100,000 colors, and `swatch.load` merges a file of 100,000 colors in under 0.1 s (it took 9.6 s of CPU in a test build). No readiness percentage change.
- **2026-10-11** · `transform.move {copy}`, Edit › Duplicate and Step and Repeat return the copies' ids, so a script can go on with them. No readiness percentage change.
- **2026-10-11** · `object.fill` and `object.stroke` refuse a swatch name the document doesn't have (it painted nothing) and suggest the name meant (`Paper` → `[Paper]`). No readiness percentage change.
+ - **2026-10-13** · Dropping an `.ase` file on the window loads its swatches, as Load Swatches does (the drop failed with "Can't Place the File"). No readiness percentage change.
- **2026-10-11 (printing):** `file.printers` and `file.print` use craft-libs/craft-print for CUPS and Windows. DesignCraft retains PDF export, page selection, spreads, marks and bleed; dry runs create no temporary PDF or print job. Windows selects matching or default driver paper and shrinks oversized sheets without enlarging smaller ones; queue duplex defaults are preserved. Headless tests exercise exported bytes, job settings, dry runs and refusals; shared native Windows CI passes, including paused-queue submission and cleanup. PostScript, production print controls and physical output validation remain open. No readiness percentage change.
- **2026-10-10 (UI.4–UI.5):** Panel tabs can move into other groups, split the dock, float, resize and return to their saved locations through shared docking transactions. Layouts persist in custom workspaces; UI and control commands share the same validated action path. Shared pane geometry and widget-state theme application retain all five palettes and local fonts. Split panes send keyboard input only to the focused canvas and scope contextual toolbar IDs per pane. No readiness percentage change.
diff --cc crates/ui-egui/src/dialogs.rs
index 39e5fa870,7d02776a2..a9b70a043
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@@ -1769,182 -2085,128 +2319,134 @@@ pub fn show(app: &mut DesignApp, ctx: &
}
});
});
- }
- }
- "closeDocument" => {
- let text = crate::i18n::tr(&app.ui.language, "“{}” has changes that are not saved. Save them before closing?").replace("{}", &d.s("title"));
- crate::rtl::label(ui, text);
- }
- "newWorkspace" => {
- ui.horizontal(|ui| {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Name:"));
- text_field(ui, &mut d, "name", 220.0);
- });
- crate::rtl::label(ui, egui::RichText::new(crate::i18n::tr(&app.ui.language, "Saves which bars show and where the panels are.")).size(10.5));
- }
- "fittingOptions" => {
- check(ui, &mut d, "autoFit", crate::i18n::tr(&app.ui.language, "Auto-Fit"));
- ui.add_space(4.0);
- crate::rtl::label(ui, egui::RichText::new(crate::i18n::tr(&app.ui.language, "Content Fitting")).font(semibold(12.0)));
- let cur = d.s("fitting");
- let label = |v: &str| match v {
- "fillProportionally" => crate::i18n::tr(&app.ui.language, "Fill Frame Proportionally"),
- "fitProportionally" => crate::i18n::tr(&app.ui.language, "Fit Content Proportionally"),
- "fitContentToFrame" => crate::i18n::tr(&app.ui.language, "Fit Content to Frame"),
- "centerContent" => crate::i18n::tr(&app.ui.language, "Center Content"),
- _ => crate::i18n::tr(&app.ui.language, "None"),
- };
- ui.horizontal(|ui| {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Fitting:"));
- egui::ComboBox::from_id_salt("ff_fit").selected_text(crate::rtl::widget(ui, label(&cur))).width(200.0).show_ui(ui, |ui| {
- for v in ["none", "fillProportionally", "fitProportionally", "fitContentToFrame", "centerContent"] {
- if ui.selectable_label(cur == v, crate::rtl::widget(ui, label(v))).clicked() {
- d.fields.insert("fitting".into(), json!(v));
- }
+ crate::rtl::label(ui, egui::RichText::new(crate::i18n::tr(&app.ui.language, "Crop Amount")).font(semibold(12.0)));
+ egui::Grid::new("ff_crop").num_columns(4).spacing([8.0, 6.0]).show(ui, |ui| {
+ for (k, l) in [("cropTop", "Top:"), ("cropLeft", "Left:")] {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, l));
+ text_field(ui, &mut d, k, 70.0);
+ }
+ ui.end_row();
+ for (k, l) in [("cropBottom", "Bottom:"), ("cropRight", "Right:")] {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, l));
+ text_field(ui, &mut d, k, 70.0);
}
+ ui.end_row();
});
- });
- ui.horizontal(|ui| {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Align From:"));
- let a = d.n("align").unwrap_or(4.0) as u8;
- egui::Grid::new("ff_align").spacing([2.0, 2.0]).show(ui, |ui| {
- for row in 0..3u8 {
- for col in 0..3u8 {
- let i = row * 3 + col;
- let (r, resp) = ui.allocate_exact_size(egui::vec2(14.0, 14.0), egui::Sense::click());
- let c = ui.visuals().text_color();
- if a == i {
- ui.painter().rect_filled(r.shrink(2.0), 1.0, c);
- } else {
- ui.painter().rect_stroke(r.shrink(3.0), 1.0, egui::Stroke::new(1.0, c), egui::StrokeKind::Inside);
- }
- if resp.clicked() {
- d.fields.insert("align".into(), json!(i));
+ }
+ "qrCode" => {
+ let cur = d.s("type");
+ ui.horizontal(|ui| {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Type:"));
+ let label = |v: &str| match v {
+ "text" => crate::i18n::tr(&app.ui.language, "Plain Text"),
+ "sms" => crate::i18n::tr(&app.ui.language, "Text Message"),
+ "email" => crate::i18n::tr(&app.ui.language, "Email"),
+ "vcard" => crate::i18n::tr(&app.ui.language, "Business Card"),
+ _ => crate::i18n::tr(&app.ui.language, "Web Hyperlink"),
+ };
+ egui::ComboBox::from_id_salt("qr_type").selected_text(crate::rtl::widget(ui, label(&cur))).width(160.0).show_ui(ui, |ui| {
+ for v in ["url", "text", "sms", "email", "vcard"] {
+ if ui.selectable_label(cur == v, crate::rtl::widget(ui, label(v))).clicked() {
+ d.fields.insert("type".into(), json!(v));
}
}
- ui.end_row();
- }
+ });
});
- });
- crate::rtl::label(ui, egui::RichText::new(crate::i18n::tr(&app.ui.language, "Crop Amount")).font(semibold(12.0)));
- egui::Grid::new("ff_crop").num_columns(4).spacing([8.0, 6.0]).show(ui, |ui| {
- for (k, l) in [("cropTop", "Top:"), ("cropLeft", "Left:")] {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, l));
- text_field(ui, &mut d, k, 70.0);
- }
- ui.end_row();
- for (k, l) in [("cropBottom", "Bottom:"), ("cropRight", "Right:")] {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, l));
- text_field(ui, &mut d, k, 70.0);
- }
- ui.end_row();
- });
- }
- "qrCode" => {
- let cur = d.s("type");
- ui.horizontal(|ui| {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Type:"));
- let label = |v: &str| match v {
- "text" => crate::i18n::tr(&app.ui.language, "Plain Text"),
- "sms" => crate::i18n::tr(&app.ui.language, "Text Message"),
- "email" => crate::i18n::tr(&app.ui.language, "Email"),
- "vcard" => crate::i18n::tr(&app.ui.language, "Business Card"),
- _ => crate::i18n::tr(&app.ui.language, "Web Hyperlink"),
+ let fields: &[(&str, &str)] = match cur.as_str() {
+ "sms" => &[("number", "Cell Number:"), ("message", "Message:")],
+ "email" => &[("to", "Email Address:"), ("subject", "Subject:"), ("body", "Message:")],
+ "vcard" => &[("name", "Name:"), ("org", "Organization:"), ("phone", "Phone:"), ("email", "Email:"), ("url", "URL:")],
+ "text" => &[("content", "Text:")],
+ _ => &[("content", "URL:")],
};
- egui::ComboBox::from_id_salt("qr_type").selected_text(crate::rtl::widget(ui, label(&cur))).width(160.0).show_ui(ui, |ui| {
- for v in ["url", "text", "sms", "email", "vcard"] {
- if ui.selectable_label(cur == v, crate::rtl::widget(ui, label(v))).clicked() {
- d.fields.insert("type".into(), json!(v));
- }
+ egui::Grid::new("qr_fields").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {
+ for (k, l) in fields {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, l));
+ text_field(ui, &mut d, k, 260.0);
+ ui.end_row();
}
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Color:"));
+ text_field(ui, &mut d, "color", 160.0);
+ ui.end_row();
});
- });
- let fields: &[(&str, &str)] = match cur.as_str() {
- "sms" => &[("number", "Cell Number:"), ("message", "Message:")],
- "email" => &[("to", "Email Address:"), ("subject", "Subject:"), ("body", "Message:")],
- "vcard" => &[("name", "Name:"), ("org", "Organization:"), ("phone", "Phone:"), ("email", "Email:"), ("url", "URL:")],
- "text" => &[("content", "Text:")],
- _ => &[("content", "URL:")],
- };
- egui::Grid::new("qr_fields").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {
- for (k, l) in fields {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, l));
- text_field(ui, &mut d, k, 260.0);
+ }
+ "polygonSettings" => {
+ egui::Grid::new("poly").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Number of Sides:"));
+ text_field(ui, &mut d, "sides", 60.0);
ui.end_row();
- }
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Color:"));
- text_field(ui, &mut d, "color", 160.0);
- ui.end_row();
- });
- }
- "polygonSettings" => {
- egui::Grid::new("poly").num_columns(2).spacing([8.0, 6.0]).show(ui, |ui| {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Number of Sides:"));
- text_field(ui, &mut d, "sides", 60.0);
- ui.end_row();
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Star Inset:"));
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Star Inset:"));
+ ui.horizontal(|ui| {
+ text_field(ui, &mut d, "starInset", 60.0);
+ ui.label("%");
+ });
+ ui.end_row();
+ });
+ }
+ STEP_AND_REPEAT => step_and_repeat_dialog(app, ui, &mut d),
+ TOC => toc_dialog(app, ui, &mut d),
+ id if id.starts_with("cmd:") => command_form(app, ui, &mut d),
+ "goToPage" => {
ui.horizontal(|ui| {
- text_field(ui, &mut d, "starInset", 60.0);
- ui.label("%");
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Page"));
+ text_field(ui, &mut d, "page", 80.0);
});
- ui.end_row();
- });
- }
- STEP_AND_REPEAT => step_and_repeat_dialog(app, ui, &mut d),
- id if id.starts_with("cmd:") => command_form(app, ui, &mut d),
- "goToPage" => {
- ui.horizontal(|ui| {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Page"));
- text_field(ui, &mut d, "page", 80.0);
- });
- }
- "ruby" => {
- ui.horizontal(|ui| {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Ruby:"));
- text_field(ui, &mut d, "text", 200.0);
- });
- crate::rtl::label(ui, egui::RichText::new(crate::i18n::tr(&app.ui.language, "Set over the selected text; empty removes it.")).size(11.0));
- }
- "insertTable" => {
- crate::rtl::label(ui, egui::RichText::new(crate::i18n::tr(&app.ui.language, "Table Dimensions")).font(semibold(12.0)));
- egui::Grid::new("ins_table").num_columns(4).spacing([8.0, 6.0]).show(ui, |ui| {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Body Rows"));
- text_field(ui, &mut d, "bodyRows", 60.0);
- crate::rtl::label(ui, crate::i18n::tr_context(&app.ui.language, "Columns", "table"));
- text_field(ui, &mut d, "columns", 60.0);
- ui.end_row();
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Header Rows"));
- text_field(ui, &mut d, "headerRows", 60.0);
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Footer Rows"));
- text_field(ui, &mut d, "footerRows", 60.0);
- ui.end_row();
- });
- }
- "textFrameOptions" => {
- seed_text_frame_options(app, &mut d);
- text_frame_options_dialog(app, ui, &mut d);
- }
- "documentSetup" => {
- // Adjust Layout applies at once.
- let adjust = document_setup(app, ui, &mut d);
- if adjust {
- result = Some(true);
}
- }
- "pdfExport" => pdf_export(app, ui, &mut d),
- "alert" => {
- let file = d.s("file");
- if !file.is_empty() {
- crate::rtl::label(ui, egui::RichText::new(crate::rtl::isolate(&file)).font(semibold(13.0)));
- ui.add_space(4.0);
+ "ruby" => {
+ ui.horizontal(|ui| {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Ruby:"));
+ text_field(ui, &mut d, "text", 200.0);
+ });
+ crate::rtl::label(
+ ui,
+ egui::RichText::new(crate::i18n::tr(&app.ui.language, "Set over the selected text; empty removes it.")).size(11.0),
+ );
}
- crate::rtl::label(ui, d.s("message"));
- }
- _ => {}
- }
- });
+ "insertTable" => {
+ crate::rtl::label(ui, egui::RichText::new(crate::i18n::tr(&app.ui.language, "Table Dimensions")).font(semibold(12.0)));
+ egui::Grid::new("ins_table").num_columns(4).spacing([8.0, 6.0]).show(ui, |ui| {
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Body Rows"));
+ text_field(ui, &mut d, "bodyRows", 60.0);
+ crate::rtl::label(ui, crate::i18n::tr_context(&app.ui.language, "Columns", "table"));
+ text_field(ui, &mut d, "columns", 60.0);
+ ui.end_row();
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Header Rows"));
+ text_field(ui, &mut d, "headerRows", 60.0);
+ crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Footer Rows"));
+ text_field(ui, &mut d, "footerRows", 60.0);
+ ui.end_row();
+ });
+ }
+ "createGuides" => create_guides_dialog(app, ui, &mut d),
+ "marginsAndColumns" => margins_and_columns_dialog(app, ui, &mut d),
+ "textFrameOptions" => {
+ seed_text_frame_options(app, &mut d);
+ text_frame_options_dialog(app, ui, &mut d);
+ }
- "documentSetup" => document_setup(app, ui, &mut d),
++ "documentSetup" => {
++ // Adjust Layout applies at once.
++ let adjust = document_setup(app, ui, &mut d);
++ if adjust {
++ result = Some(true);
++ }
++ }
+ "pdfExport" => pdf_export(app, ui, &mut d),
+ "alert" => {
+ let file = d.s("file");
+ if !file.is_empty() {
+ crate::rtl::label(ui, egui::RichText::new(crate::rtl::isolate(&file)).font(semibold(13.0)));
+ ui.add_space(4.0);
+ }
+ crate::rtl::label(ui, d.s("message"));
+ }
+ _ => {}
+ });
ui.add_space(12.0);
- let ok_label = if d.id == "closeDocument" { " Save " } else { " OK " };
+ let ok_label = match d.id.as_str() {
+ "closeDocument" => " Save ",
+ "updateLink" => " Update ",
+ _ => " OK ",
+ };
ui.horizontal(|ui| {
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui
@@@ -4263,103 -5101,722 +5342,819 @@@ mod tests
}
}
+ /// A three-page document in `units` with Document Setup open.
+ fn document_setup_app(units: &str) -> DesignApp {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({"pages": 3})).unwrap();
+ app.run("document.preferences", json!({"horizontalUnits": units, "verticalUnits": units})).unwrap();
+ crate::menus::activate(&mut app, "layout.documentSetup", &Value::Null);
+ app
+ }
+
+ fn setup_fields(app: &mut DesignApp, fields: Value) {
+ let d = app.ui.dialog.as_mut().unwrap();
+ for (k, v) in fields.as_object().unwrap() {
+ d.fields.insert(k.clone(), v.clone());
+ }
+ }
+
+ #[test]
+ fn document_setup_ok_applies_margins_bleed_and_size_in_one_step() {
+ let mut app = document_setup_app("millimeters");
+ let d = app.ui.dialog.as_ref().unwrap();
+ assert_eq!(d.id, "documentSetup");
+ assert_eq!((d.s("marginTop"), d.b("marginLinked")), ("12.7 mm".to_string(), true), "the document's margins, in its units");
+ setup_fields(
+ &mut app,
+ json!({"marginTop": "20 mm", "marginBottom": "20 mm", "marginInside": "20 mm", "marginOutside": "20 mm", "bleedTop": "3 mm",
+ "bleedBottom": "3 mm", "bleedInside": "3 mm", "bleedOutside": "3 mm", "width": "210 mm", "height": "297 mm"}),
+ );
+ confirm(&mut app).unwrap();
+ assert!(app.ui.dialog.is_none());
+ let mm = designcraft_geom::units::PT_PER_MM;
+ let doc = &app.session.active().unwrap().doc;
+ assert!((doc.settings.page_width - 210.0 * mm).abs() < 1e-6 && (doc.settings.bleed[2] - 3.0 * mm).abs() < 1e-6);
+ assert!(doc.spreads.iter().flat_map(|s| &s.pages).all(|p| (p.margins.top - 20.0 * mm).abs() < 1e-6), "every page");
+ app.run("edit.undo", json!({})).unwrap();
+ let doc = &app.session.active().unwrap().doc;
+ assert!((doc.settings.page_width - 612.0).abs() < 1e-6 && doc.settings.bleed[0] == 0.0, "one undo step");
+ }
+
+ #[test]
+ fn document_setup_keeps_each_pages_margins_unless_they_are_edited() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({"pages": 3, "margins": 36})).unwrap();
+ app.run("layout.marginsAndColumns", json!({"pages": [1], "margins": 90})).unwrap();
+ let margins =
+ |app: &DesignApp| app.session.active().unwrap().doc.spreads.iter().flat_map(|s| &s.pages).map(|p| p.margins.top).collect::<Vec<_>>();
+ // Only the page count changes: every page keeps its own margins.
+ crate::menus::activate(&mut app, "layout.documentSetup", &Value::Null);
+ setup_fields(&mut app, json!({"pages": "4"}));
+ confirm(&mut app).unwrap();
+ assert_eq!(margins(&app), [36.0, 90.0, 36.0, 36.0]);
+ // Edited margins go to every page.
+ crate::menus::activate(&mut app, "layout.documentSetup", &Value::Null);
+ setup_fields(&mut app, json!({"marginTop": "1p0"}));
+ confirm(&mut app).unwrap();
+ assert_eq!(margins(&app), [12.0; 4]);
+ }
+
+ #[test]
+ fn document_setup_keeps_a_value_it_cannot_read_and_changes_nothing() {
+ for (key, value) in [("width", "wide"), ("marginTop", "-"), ("pages", "0"), ("bleedTop", "x")] {
+ let mut app = document_setup_app("points");
+ setup_fields(&mut app, json!({key: value, "bleedInside": "9"}));
+ assert!(confirm(&mut app).is_err(), "{key}");
+ assert!(app.ui.dialog.is_some(), "{key}: the dialog stays open");
+ assert_eq!(app.session.active().unwrap().doc.settings.bleed, [0.0; 4], "{key}: nothing changed");
+ }
+ }
+
+ #[test]
+ fn document_setup_links_edges_and_adjust_layout_applies() {
+ let mut app = document_setup_app("points");
+ let f = app.run("frame.create", json!({"rect": [36, 36, 576, 756], "content": "text"})).unwrap();
+ crate::menus::activate(&mut app, "layout.documentSetup", &Value::Null);
+ let ctx = dialog_context("en");
+ let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1178.0, 900.0));
+ for _ in 0..3 {
+ dialog_frame(&mut app, &ctx, screen, vec![]);
+ }
+ // Typing in a linked margin sets all four.
+ let labels = dialog_frame(&mut app, &ctx, screen, vec![]);
+ let top = labels.iter().filter(|(t, _, _)| t == "36 pt").map(|(_, r, _)| *r).next().expect("the top margin");
+ click_dialog(&mut app, &ctx, screen, top.center());
+ let select_all =
+ egui::Event::Key { key: egui::Key::A, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::COMMAND };
+ dialog_frame(&mut app, &ctx, screen, vec![select_all, egui::Event::Text("72 pt".into())]);
+ dialog_frame(&mut app, &ctx, screen, vec![]);
+ let d = app.ui.dialog.as_ref().unwrap();
+ assert!(["Top", "Bottom", "Inside", "Outside"].iter().all(|e| d.s(&format!("margin{e}")) == "72 pt"), "linked: {:?}", d.fields);
+ // Adjust Layout applies at once, and the frame follows the margins.
+ let labels = dialog_frame(&mut app, &ctx, screen, vec![]);
+ click_dialog(&mut app, &ctx, screen, visible_label(&labels, screen, "Adjust Layout").center());
+ assert!(app.ui.dialog.is_none(), "applied");
+ let doc = &app.session.active().unwrap().doc;
+ let b = doc.item(designcraft_doc::ItemId(f["id"].as_u64().unwrap())).unwrap().bounds();
+ assert!((b.y0 - 72.0).abs() < 1e-6 && doc.page(0).unwrap().margins.outside == 72.0, "{b:?}");
+ }
+
+ fn scope_control(app: &mut DesignApp, ctx: &egui::Context, method: &str, params: Value) -> Value {
+ let (request, _reply) = crate::control::ControlRequest::new(method, params);
+ let crate::control::Outcome::Done(value) = crate::control::handle(app, ctx, &request) else { panic!("ordinary control response") };
+ assert_eq!(value["ok"], true, "{value}");
+ value["result"].clone()
+ }
+
+ fn scope_click(app: &mut DesignApp, ctx: &egui::Context, screen: egui::Rect, label: &str) {
+ let labels = dialog_frame(app, ctx, screen, vec![]);
+ let pos = visible_label(&labels, screen, label).center();
+ click_dialog(app, ctx, screen, pos);
+ }
+
+ fn scope_dialog() -> (DesignApp, egui::Context, egui::Rect, designcraft_engine::doc::StoryId) {
+ scope_dialog_with_selection("red red | red", 7)
+ }
+
+ fn scope_dialog_with_selection(text: &str, end: usize) -> (DesignApp, egui::Context, egui::Rect, designcraft_engine::doc::StoryId) {
+ scope_dialog_with_tool(text, end, None)
+ }
+
+ fn scope_dialog_with_tool(
+ text: &str,
+ end: usize,
+ tool: Option<&str>,
+ ) -> (DesignApp, egui::Context, egui::Rect, designcraft_engine::doc::StoryId) {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.ui.language = "en".into();
+ app.run("file.new", json!({})).unwrap();
+ let frame = app.run("frame.create", json!({"rect": [36, 36, 100, 100], "content": "text", "text": text})).unwrap();
+ let sid = designcraft_engine::doc::StoryId(frame["story"].as_u64().unwrap());
+ let ctx = dialog_context("en");
+ if let Some(tool) = tool {
+ scope_control(&mut app, &ctx, "ui.tool.select", json!({"tool": tool}));
+ }
+ app.run("text.select", json!({"story": sid.0, "anchor": 0, "focus": end})).unwrap();
+ app.run("app.findChange", json!({})).unwrap();
+ let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1178.0, 814.0));
+ for (field, value) in [("find", "red"), ("change", "unused")] {
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": field, "value": value}));
+ }
+ for _ in 0..3 {
+ dialog_frame(&mut app, &ctx, screen, vec![]);
+ }
+ scope_click(&mut app, &ctx, screen, "document");
+ scope_click(&mut app, &ctx, screen, "selection");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("scope"), "selection");
+ (app, ctx, screen, sid)
+ }
+
+ fn scope_selected(app: &DesignApp, sid: designcraft_engine::doc::StoryId, a: usize, b: usize) {
+ let t = app.session.doc().unwrap().selection.text.unwrap();
+ assert_eq!((t.story, t.range(), t.cell), (sid, a..b, None));
+ }
+
+ fn scope_state_unchanged(app: &DesignApp, before: &designcraft_engine::DocState) {
+ let after = app.session.doc().unwrap();
+ assert!(std::sync::Arc::ptr_eq(&before.doc, &after.doc));
+ assert_eq!(after.uid, before.uid);
+ assert_eq!(after.revision, before.revision);
+ assert_eq!(after.selection, before.selection);
+ assert_eq!(after.history.limit, before.history.limit);
+ for (actual, expected) in [(&after.history.undo, &before.history.undo), (&after.history.redo, &before.history.redo)] {
+ assert_eq!(actual.len(), expected.len());
+ for (a, b) in actual.iter().zip(expected) {
+ assert_eq!(a.label, b.label);
+ assert_eq!(a.selection, b.selection);
+ assert!(std::sync::Arc::ptr_eq(&a.doc, &b.doc));
+ }
+ }
+ }
+
+ #[test]
+ fn find_scope_dialog_control_effective_noops_retain_bounds() {
+ for (field, value) in [("objectMode", json!(false)), ("story", Value::Null)] {
+ let (mut app, ctx, screen, sid) = scope_dialog();
+ assert!(!app.ui.dialog.as_ref().unwrap().fields.contains_key(field));
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "change", "value": "blue"}));
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ let before = app.session.doc().unwrap().clone();
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": field, "value": value}));
+ assert_eq!(app.ui.dialog.as_ref().unwrap().fields[field], value);
+ scope_state_unchanged(&app, &before);
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 4, 7);
+ scope_click(&mut app, &ctx, screen, "Change All");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 replacement(s) made");
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, "blue blue | red");
+ assert_eq!(app.session.doc().unwrap().history.undo.len(), before.history.undo.len() + 1);
+ }
+ }
+
+ #[test]
+ fn find_scope_dialog_explicit_story_ignored_scope_preserves_grep_cursor() {
+ for physical in [false, true] {
+ for (text, pattern, hits, changed) in [
+ ("é", "é|(?:)", vec![(0, 2)], "X"),
+ ("é🙂", "é|(?:)", vec![(0, 2), (6, 6)], "X🙂X"),
+ ("é🙂", "(?:)", vec![(0, 0), (2, 2), (6, 6)], "XéX🙂X"),
+ ] {
+ let (mut app, ctx, screen, sid) = scope_dialog_with_selection(text, 0);
+ for (field, value) in [("find", json!(pattern)), ("change", json!("X")), ("story", json!(sid.0))] {
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": field, "value": value}));
+ }
+ scope_click(&mut app, &ctx, screen, "GREP");
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), format!("{} match(es)", hits.len()));
+ for &(a, b) in &hits {
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "Found");
+ scope_selected(&app, sid, a, b);
+ let before = app.session.doc().unwrap().clone();
+ let cur = app.ui.dialog.as_ref().unwrap().s("scope");
+ let next = if cur == "selection" { "document" } else { "selection" };
+ if physical {
+ scope_click(&mut app, &ctx, screen, &cur);
+ scope_click(&mut app, &ctx, screen, next);
+ } else {
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "scope", "value": next}));
+ }
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("scope"), next);
+ assert_eq!(app.ui.dialog.as_ref().unwrap().fields["story"], json!(sid.0));
+ scope_state_unchanged(&app, &before);
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), format!("{} match(es)", hits.len()));
+ }
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "No matches");
+ // An ignored scope change must not revive an exhausted endpoint either.
+ let before = app.session.doc().unwrap().clone();
+ let cur = app.ui.dialog.as_ref().unwrap().s("scope");
+ let next = if cur == "selection" { "document" } else { "selection" };
+ if physical {
+ scope_click(&mut app, &ctx, screen, &cur);
+ scope_click(&mut app, &ctx, screen, next);
+ } else {
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "scope", "value": next}));
+ }
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "No matches");
+ scope_state_unchanged(&app, &before);
+ scope_click(&mut app, &ctx, screen, "Change All");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), format!("{} replacement(s) made", hits.len()));
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, changed);
+ }
+ }
+ }
+
+ #[test]
+ fn find_scope_dialog_explicit_story_transitions_reset_cursor() {
+ for remove_override in [false, true] {
+ let (mut app, ctx, screen, sid) = scope_dialog_with_selection("é🙂", 0);
+ let other = app.run("frame.create", json!({"rect": [180, 36, 100, 100], "content": "text", "text": "other"})).unwrap();
+ app.run("text.select", json!({"story": sid.0, "anchor": 0, "focus": 0})).unwrap();
+ for (field, value) in [("find", json!("(?:)")), ("story", json!(sid.0))] {
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": field, "value": value}));
+ }
+ scope_click(&mut app, &ctx, screen, "GREP");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 0);
+ let before = app.session.doc().unwrap().clone();
+ let value = if remove_override { Value::Null } else { other["story"].clone() };
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "story", "value": value}));
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "story", "value": sid.0}));
+ scope_state_unchanged(&app, &before);
+ // Away and back still releases continuation even if no Find command intervenes.
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 0);
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 2, 2);
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, "é🙂");
+ let other_sid = designcraft_engine::doc::StoryId(other["story"].as_u64().unwrap());
+ assert_eq!(app.session.doc().unwrap().doc.story(other_sid).unwrap().text, "other");
+ }
+ }
+
+ #[test]
+ fn find_scope_dialog_control_mode_changes_release_bounds() {
+ for object_mode in [false, true] {
+ let (mut app, ctx, _, sid) = scope_dialog();
+ if object_mode {
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "objectMode", "value": true}));
+ }
+ // Direct Session consumers share the retained domain even while Object is shown.
+ let p = json!({"find": "red", "change": "blue", "scope": "selection"});
+ let count = scope_control(&mut app, &ctx, "engine.execute", json!({"command": "find.find", "params": p}));
+ assert_eq!(count.as_array().unwrap().len(), 2);
+ scope_control(&mut app, &ctx, "engine.execute", json!({"command": "find.next", "params": p}));
+ scope_selected(&app, sid, 0, 3);
+ let before = app.session.doc().unwrap().clone();
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "objectMode", "value": !object_mode}));
+ assert_eq!(app.ui.dialog.as_ref().unwrap().b("objectMode"), !object_mode);
+ scope_state_unchanged(&app, &before);
+ let count = scope_control(&mut app, &ctx, "engine.execute", json!({"command": "find.find", "params": p}));
+ assert_eq!(count, json!([{"story": sid.0, "start": 0, "end": 3, "text": "red"}]));
+ let changed = scope_control(&mut app, &ctx, "engine.execute", json!({"command": "find.change", "params": p}));
+ assert_eq!(changed, json!({"count": 1}));
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, "blue red | red");
+ }
+ }
+
+ #[test]
+ fn find_scope_dialog_tool_replacement_releases_bounds() {
+ for (tool, replacement) in [("page", "cmd:layout.pageSize"), ("rectangleFrame", "frameSize")] {
+ let (mut app, ctx, screen, sid) = scope_dialog_with_tool("red red | red", 7, Some(tool));
+ assert_eq!(app.session.tool_id(), tool);
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ let before = app.session.doc().unwrap().clone();
+ let active = (app.session.active_index(), app.session.documents().len());
+ let off = app.session.layout().xf(designcraft_engine::doc::SpreadRef::Doc(0)).translation();
+ let x = off.x + before.doc.spreads[0].pages[0].x + 200.0;
+ let y = off.y + 200.0;
+ // The Page tool opens Page Size on a double-click (a click selects the page).
+ let events = if tool == "page" {
+ json!([{"kind": "doubleclick", "x": x, "y": y}])
+ } else {
+ json!([{"kind": "down", "x": x, "y": y}, {"kind": "up", "x": x, "y": y}])
+ };
+ // Real tool -> Action::Dialog -> after_engine; no injected UI request.
+ scope_control(&mut app, &ctx, "ui.pointer", json!({"events": events}));
+ assert_eq!(app.ui.dialog.as_ref().unwrap().id, replacement);
+ assert!(app.session.ui_requests.is_empty());
+ assert_eq!((app.session.active_index(), app.session.documents().len()), active);
+ scope_state_unchanged(&app, &before);
+ scope_click(&mut app, &ctx, screen, "Cancel");
+ assert!(app.ui.dialog.is_none());
+ assert_eq!((app.session.active_index(), app.session.documents().len()), active);
+ scope_state_unchanged(&app, &before);
+ let p = json!({"find": "red", "change": "blue", "scope": "selection"});
+ let count = scope_control(&mut app, &ctx, "engine.execute", json!({"command": "find.find", "params": p}));
+ assert_eq!(count, json!([{"story": sid.0, "start": 0, "end": 3, "text": "red"}]));
+ scope_state_unchanged(&app, &before);
+ let changed = scope_control(&mut app, &ctx, "engine.execute", json!({"command": "find.change", "params": p}));
+ assert_eq!(changed, json!({"count": 1}));
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, "blue red | red");
+ assert_eq!(app.session.doc().unwrap().history.undo.len(), before.history.undo.len() + 1);
+ }
+ }
+
+ #[test]
+ fn find_scope_dialog_tool_without_replacement_retains_bounds() {
+ for tool in ["page", "rectangleFrame"] {
+ let (mut app, ctx, screen, sid) = scope_dialog_with_tool("red red | red", 7, Some(tool));
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "change", "value": "blue"}));
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ let before = app.session.doc().unwrap().clone();
+ let fields = app.ui.dialog.as_ref().unwrap().fields.clone();
+ scope_control(&mut app, &ctx, "ui.pointer", json!({"events": [{"kind": "move", "x": 200, "y": 200}]}));
+ assert_eq!(app.ui.dialog.as_ref().unwrap().id, "findChange");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().fields, fields);
+ scope_state_unchanged(&app, &before);
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 4, 7);
+ scope_click(&mut app, &ctx, screen, "Change All");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 replacement(s) made");
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, "blue blue | red");
+ }
+ }
+
+ #[cfg(not(target_arch = "wasm32"))]
+ #[test]
+ fn find_scope_dialog_native_pdf_replacement_releases_bounds() {
+ let directory = tempfile::tempdir().unwrap();
+ let path = directory.path().join("three.pdf");
+ std::fs::write(&path, crate::browser_import_tests::pdf()).unwrap();
+ for dismissal in ["Cancel", "Escape", "control"] {
+ let (mut app, ctx, screen, sid) = scope_dialog();
+ let picked = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));
+ let read = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));
+ let seen_pick = picked.clone();
+ let seen_read = read.clone();
+ let pick_path = path.to_string_lossy().to_string();
+ let read_path = pick_path.clone();
+ app.services.pick_open = Some(Box::new(move |purpose| {
+ assert_eq!(purpose, "place");
+ seen_pick.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
+ Some(pick_path.clone())
+ }));
+ app.services.read = Some(Box::new(move |path| {
+ assert_eq!(path, read_path);
+ seen_read.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
+ std::fs::read(path).map_err(|e| e.to_string())
+ }));
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ let before = app.session.doc().unwrap().clone();
+ let active = (app.session.active_index(), app.session.documents().len());
+ // Exercise engine.execute -> UiRequest::Pick -> native host PDF replacement.
+ scope_control(&mut app, &ctx, "engine.execute", json!({"command": "file.place", "params": {}}));
+ assert_eq!(picked.load(std::sync::atomic::Ordering::SeqCst), 1);
+ assert_eq!(read.load(std::sync::atomic::Ordering::SeqCst), 1);
+ let dialog = app.ui.dialog.as_ref().unwrap();
+ assert_eq!(dialog.id, "pdfImport");
+ assert_eq!(dialog.s("path"), path.to_string_lossy());
+ assert_eq!(dialog.fields["pages"], 3);
+ assert_eq!(dialog.s("page"), "1");
+ assert!(!dialog.b("async"));
+ assert_eq!(dialog.fields["target"], json!(before.uid));
+ assert!(app.session.ui_requests.is_empty());
+ assert!(app.pending_pdf.is_none());
+ assert_eq!((app.session.active_index(), app.session.documents().len()), active);
+ scope_state_unchanged(&app, &before);
+ match dismissal {
+ "Cancel" => scope_click(&mut app, &ctx, screen, "Cancel"),
+ "Escape" => {
+ dialog_frame(
+ &mut app,
+ &ctx,
+ screen,
+ vec![egui::Event::Key {
+ key: egui::Key::Escape,
+ physical_key: None,
+ pressed: true,
+ repeat: false,
+ modifiers: egui::Modifiers::NONE,
+ }],
+ );
+ }
+ "control" => {
+ scope_control(&mut app, &ctx, "ui.dialog.cancel", json!({}));
+ }
+ _ => panic!("known dismissal"),
+ }
+ assert!(app.ui.dialog.is_none());
+ assert!(app.pending_pdf.is_none());
+ assert_eq!(picked.load(std::sync::atomic::Ordering::SeqCst), 1);
+ assert_eq!(read.load(std::sync::atomic::Ordering::SeqCst), 1);
+ assert_eq!((app.session.active_index(), app.session.documents().len()), active);
+ scope_state_unchanged(&app, &before);
+ let p = json!({"find": "red", "change": "blue", "scope": "selection"});
+ let count = scope_control(&mut app, &ctx, "engine.execute", json!({"command": "find.find", "params": p}));
+ assert_eq!(count, json!([{"story": sid.0, "start": 0, "end": 3, "text": "red"}]));
+ scope_state_unchanged(&app, &before);
+ let changed = scope_control(&mut app, &ctx, "engine.execute", json!({"command": "find.change", "params": p}));
+ assert_eq!(changed, json!({"count": 1}));
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, "blue red | red");
+ assert_eq!(app.session.doc().unwrap().history.undo.len(), before.history.undo.len() + 1);
+ }
+ }
+
+ #[cfg(not(target_arch = "wasm32"))]
+ #[test]
+ fn find_scope_dialog_native_picker_cancel_retains_bounds() {
+ let (mut app, ctx, screen, sid) = scope_dialog();
+ let picked = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));
+ let seen = picked.clone();
+ app.services.pick_open = Some(Box::new(move |purpose| {
+ assert_eq!(purpose, "place");
+ seen.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
+ None
+ }));
+ let read = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));
+ let seen_read = read.clone();
+ app.services.read = Some(Box::new(move |_| {
+ seen_read.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
+ Err("canceled picker must not read".into())
+ }));
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "change", "value": "blue"}));
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ let before = app.session.doc().unwrap().clone();
+ let active = (app.session.active_index(), app.session.documents().len());
+ let fields = app.ui.dialog.as_ref().unwrap().fields.clone();
+ scope_control(&mut app, &ctx, "engine.execute", json!({"command": "file.place", "params": {}}));
+ assert_eq!(picked.load(std::sync::atomic::Ordering::SeqCst), 1);
+ assert_eq!(read.load(std::sync::atomic::Ordering::SeqCst), 0);
+ assert_eq!(app.ui.dialog.as_ref().unwrap().id, "findChange");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().fields, fields);
+ assert_eq!((app.session.active_index(), app.session.documents().len()), active);
+ scope_state_unchanged(&app, &before);
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 4, 7);
+ scope_click(&mut app, &ctx, screen, "Change All");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 replacement(s) made");
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, "blue blue | red");
+ assert_eq!(app.session.doc().unwrap().history.undo.len(), before.history.undo.len() + 1);
+ }
+
+ #[test]
+ fn find_scope_dialog_exact_baseline_buttons() {
+ let (mut app, ctx, screen, sid) = scope_dialog_with_selection("red red", 3);
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "change", "value": "blue"}));
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "1 match(es)");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ scope_click(&mut app, &ctx, screen, "Change All");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "1 replacement(s) made");
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, "blue red");
+ }
+
+ #[test]
+ fn find_scope_dialog_grep_tab_alone_restarts_original_selection() {
+ let (mut app, ctx, screen, sid) = scope_dialog();
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ scope_click(&mut app, &ctx, screen, "GREP");
+ assert!(app.ui.dialog.as_ref().unwrap().b("grep"));
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("find"), "red");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 4, 7);
+ scope_click(&mut app, &ctx, screen, "Text");
+ assert!(!app.ui.dialog.as_ref().unwrap().b("grep"));
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ }
+
+ #[test]
+ fn find_scope_dialog_buttons_retain_nonempty_hits_and_change_all() {
+ let (mut app, ctx, screen, sid) = scope_dialog();
+ let history = app.session.doc().unwrap().history.undo.len();
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "change", "value": "blue"}));
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 4, 7);
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "No matches");
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ assert_eq!(app.session.doc().unwrap().history.undo.len(), history);
+ scope_click(&mut app, &ctx, screen, "Change All");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 replacement(s) made");
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, "blue blue | red");
+ assert_eq!(app.session.doc().unwrap().history.undo.len(), history + 1);
+ scope_click(&mut app, &ctx, screen, "Cancel");
+ assert!(app.ui.dialog.is_none());
+ app.run("edit.undo", json!({})).unwrap();
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, "red red | red");
+ app.run("edit.redo", json!({})).unwrap();
+ let native = app.run("file.serialize", json!({})).unwrap();
+ app.run("file.openBytes", json!({"name": "scope.designcraft", "base64": native["base64"]})).unwrap();
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, "blue blue | red");
+ }
+
+ fn scope_confirm_case(action: &str) {
+ let (mut app, ctx, screen, sid) = scope_dialog();
+ scope_click(&mut app, &ctx, screen, "Count");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "change", "value": "blue"}));
+ match action {
+ "OK" => scope_click(&mut app, &ctx, screen, "OK"),
+ "Enter" => {
+ dialog_frame(
+ &mut app,
+ &ctx,
+ screen,
+ vec![egui::Event::Key {
+ key: egui::Key::Enter,
+ physical_key: None,
+ pressed: true,
+ repeat: false,
+ modifiers: egui::Modifiers::NONE,
+ }],
+ );
+ }
+ "control" => {
+ assert_eq!(scope_control(&mut app, &ctx, "ui.dialog.confirm", json!({}))["count"], 2);
+ }
+ _ => panic!("known confirmation route"),
+ }
+ assert!(app.ui.dialog.is_none());
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, "blue blue | red");
+ // The closed dialog cannot leave its old seven-byte range for a later direct query.
+ let matches = app.run("find.find", json!({"find": "blue", "scope": "selection"})).unwrap();
+ assert_eq!(matches.as_array().unwrap().len(), 0);
+ }
+
+ #[test]
+ fn find_scope_dialog_ok_consumes_retained_bounds() {
+ scope_confirm_case("OK");
+ }
+
+ #[test]
+ fn find_scope_dialog_enter_consumes_retained_bounds() {
+ scope_confirm_case("Enter");
+ }
+
+ #[test]
+ fn find_scope_dialog_control_confirm_consumes_retained_bounds() {
+ scope_confirm_case("control");
+ }
+
+ #[test]
+ fn find_scope_dialog_query_reselection_cancel_and_reopen() {
+ let (mut app, ctx, screen, sid) = scope_dialog();
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "grep", "value": true}));
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "find", "value": "r.d"}));
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ scope_control(&mut app, &ctx, "ui.dialog.cancel", json!({}));
+ assert_eq!(app.run("find.find", json!({"find": "red", "scope": "selection"})).unwrap().as_array().unwrap().len(), 1);
+ app.run("text.select", json!({"story": sid.0, "anchor": 0, "focus": 7})).unwrap();
+ app.run("find.next", json!({"find": "red", "scope": "selection"})).unwrap();
+ scope_control(&mut app, &ctx, "ui.dialog.open", json!({"id": "findChange", "fields": {"find": "red", "scope": "selection"}}));
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "1 match(es)");
+ app.run("text.select", json!({"story": sid.0, "anchor": 4, "focus": 7})).unwrap();
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 4, 7);
+ app.run("app.findChange", json!({})).unwrap();
+ for (field, value) in [("find", "red"), ("scope", "selection")] {
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": field, "value": value}));
+ }
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "1 match(es)");
+ }
+
+ #[test]
+ fn find_scope_dialog_word_reselection_limits_count_and_change_buttons() {
+ let (mut app, ctx, screen, sid) = scope_dialog();
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ let selected = app.session.doc().unwrap().selection.clone();
+ let frame = selected.text.unwrap().frame.unwrap();
+ let point = {
+ let st = app.session.doc().unwrap();
+ let cs = app.session.cache.get(&st.doc, sid, None);
+ let (fi, x, baseline, ascent, _) = designcraft_compose::caret(&cs, 1).unwrap();
+ let inner = designcraft_geom::Point::new(x, baseline - ascent * 0.5);
+ assert_eq!(cs.frames[fi].frame, frame);
+ assert_eq!(designcraft_compose::hit(&cs, fi, inner), Some(1));
+ let loc = st.doc.find(frame).unwrap();
+ st.doc.parent_xf(&loc) * st.doc.text_xf(st.doc.item(frame).unwrap()) * inner
+ };
+ let before = app.session.doc().unwrap().doc.clone();
+ let revision = app.session.doc().unwrap().revision;
+ app.run("text.selectWord", json!({"frame": frame.0, "point": [point.x, point.y]})).unwrap();
+ assert_eq!(app.session.doc().unwrap().selection, selected);
+ assert_eq!(app.session.doc().unwrap().revision, revision + 1);
+ assert!(std::sync::Arc::ptr_eq(&before, &app.session.doc().unwrap().doc));
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "1 match(es)");
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "change", "value": "blue"}));
+ scope_click(&mut app, &ctx, screen, "Change All");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "1 replacement(s) made");
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, "blue red | red");
+ }
+
+ #[cfg(not(target_arch = "wasm32"))]
+ #[test]
+ fn find_scope_dialog_failed_native_drop_alert_releases_bounds() {
+ let directory = tempfile::tempdir().unwrap();
+ let path = directory.path().join("broken.designcraft");
+ std::fs::write(&path, b"not a native document").unwrap();
+ for dismissal in ["OK", "Escape", "control"] {
+ let (mut app, ctx, screen, sid) = scope_dialog();
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "2 match(es)");
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ let before = app.session.doc().unwrap().doc.clone();
+ let selected = app.session.doc().unwrap().selection.clone();
+ let revision = app.session.doc().unwrap().revision;
+ let history = app.session.doc().unwrap().history.undo.len();
+ let uid = app.session.doc().unwrap().uid;
+ let error = app.open_dropped(&path.to_string_lossy()).unwrap_err();
+ let alert = app.ui.dialog.as_ref().unwrap();
+ assert_eq!(alert.id, "alert");
+ assert_eq!(alert.s("title"), "Can't Open the File");
+ assert_eq!(alert.s("message"), error);
+ assert!(std::sync::Arc::ptr_eq(&before, &app.session.doc().unwrap().doc));
+ assert_eq!(app.session.doc().unwrap().selection, selected);
+ assert_eq!(app.session.doc().unwrap().revision, revision);
+ assert_eq!(app.session.doc().unwrap().uid, uid);
+ assert_eq!(app.session.doc().unwrap().history.undo.len(), history);
+ match dismissal {
+ "OK" => scope_click(&mut app, &ctx, screen, "OK"),
+ "Escape" => {
+ dialog_frame(
+ &mut app,
+ &ctx,
+ screen,
+ vec![egui::Event::Key {
+ key: egui::Key::Escape,
+ physical_key: None,
+ pressed: true,
+ repeat: false,
+ modifiers: egui::Modifiers::NONE,
+ }],
+ );
+ }
+ "control" => {
+ scope_control(&mut app, &ctx, "ui.dialog.cancel", json!({}));
+ }
+ _ => panic!("known dismissal"),
+ }
+ assert!(app.ui.dialog.is_none());
+ let p = json!({"find": "red", "change": "blue", "scope": "selection"});
+ assert_eq!(app.run("find.find", p.clone()).unwrap(), json!([{"story": sid.0, "start": 0, "end": 3, "text": "red"}]));
+ assert_eq!(app.run("find.change", p).unwrap(), json!({"count": 1}));
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, "blue red | red");
+ assert_eq!(app.session.doc().unwrap().history.undo.len(), history + 1);
+ }
+ }
+
+ #[test]
+ fn find_scope_dialog_child_errors_and_explicit_parent() {
+ let (mut app, ctx, screen, sid) = scope_dialog();
+ app.run("text.select", json!({"story": sid.0, "anchor": 13, "focus": 13})).unwrap();
+ app.run("table.insert", json!({"rows": 1, "cols": 1})).unwrap();
+ app.run("text.insert", json!({"text": "red child", "raw": true})).unwrap();
+ let child = app.session.doc().unwrap().selection.text.unwrap();
+ let before = app.session.doc().unwrap().doc.clone();
+ let selection = app.session.doc().unwrap().selection.clone();
+ let history = app.session.doc().unwrap().history.undo.len();
+ for label in ["Count", "Find Next", "Change All"] {
+ scope_click(&mut app, &ctx, screen, label);
+ assert!(app.ui.dialog.as_ref().unwrap().s("status").contains("not supported"));
+ assert!(std::sync::Arc::ptr_eq(&before, &app.session.doc().unwrap().doc));
+ assert_eq!(app.session.doc().unwrap().selection, selection);
+ assert_eq!(app.session.doc().unwrap().history.undo.len(), history);
+ }
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "change", "value": "blue"}));
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "story", "value": sid.0}));
+ scope_click(&mut app, &ctx, screen, "Count");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "3 match(es)");
+ scope_click(&mut app, &ctx, screen, "Change All");
+ assert_eq!(app.ui.dialog.as_ref().unwrap().s("status"), "3 replacement(s) made");
+ assert_eq!(app.session.doc().unwrap().doc.text_story(sid, child.cell).unwrap().text, "red child");
+ assert!(app.session.doc().unwrap().doc.story(sid).unwrap().text.starts_with("blue blue | blue"));
+ }
+
+ #[test]
+ fn find_scope_dialog_error_confirmation_and_escape_release_context() {
+ for escape in [false, true] {
+ let (mut app, ctx, screen, sid) = scope_dialog();
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ scope_selected(&app, sid, 0, 3);
+ if escape {
+ dialog_frame(
+ &mut app,
+ &ctx,
+ screen,
+ vec![egui::Event::Key {
+ key: egui::Key::Escape,
+ physical_key: None,
+ pressed: true,
+ repeat: false,
+ modifiers: egui::Modifiers::NONE,
+ }],
+ );
+ } else {
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "find", "value": "["}));
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "grep", "value": true}));
+ scope_click(&mut app, &ctx, screen, "OK");
+ }
+ assert!(app.ui.dialog.is_none());
+ assert_eq!(app.session.doc().unwrap().doc.story(sid).unwrap().text, "red red | red");
+ assert_eq!(app.run("find.find", json!({"find": "red", "scope": "selection"})).unwrap().as_array().unwrap().len(), 1);
+ }
+ }
+
+ #[test]
+ fn find_scope_dialog_domain_and_object_changes_release_original_range() {
+ for route in ["scope", "object", "menu", "command"] {
+ let (mut app, ctx, screen, _) = scope_dialog();
+ scope_click(&mut app, &ctx, screen, "Find Next");
+ match route {
+ "scope" => {
+ for scope in ["story", "selection"] {
+ scope_control(&mut app, &ctx, "ui.dialog.set", json!({"field": "scope", "value": scope}));
+ }
+ }
+ "object" => {
+ scope_click(&mut app, &ctx, screen, "Object");
+ scope_click(&mut app, &ctx, screen, "Text");
+ }
+ "menu" => crate::menus::activate(&mut app, "app.newDocumentDialog", &Value::Null),
+ "command" => {
+ app.run("app.newDocumentDialog", json!({})).unwrap();
+ }
+ _ => panic!("known reset route"),
+ }
+ assert_eq!(app.run("find.find", json!({"find": "red", "scope": "selection"})).unwrap().as_array().unwrap().len(), 1);
+ }
+ }
+
#[test]
fn dialog_title_and_actions_fit_scaled_viewports() {
for language in ["en", "ar"] {
diff --cc crates/ui-egui/src/i18n.rs
index 38445f01a,245a6e287..579ecdb4d
--- a/crates/ui-egui/src/i18n.rs
+++ b/crates/ui-egui/src/i18n.rs
@@@ -2842,36 -3112,6 +3112,30 @@@ const TABLE: &[(&str, [&str; 5])] = &
("Presentation", ["Präsentation", "Présentation", "Presentación", "プレゼンテーション", "演示文稿"]),
("Extras", ["Extras", "Options supplémentaires", "Extras", "エクストラ", "附加"]),
("Column", ["Spalte", "Colonne", "Columna", "段", "栏"]),
+ // Document Setup
+ ("Page Size:", ["Seitenformat:", "Format de page :", "Tamaño de página:", "ページサイズ:", "页面大小:"]),
+ (
+ "Adjust page elements to document changes",
+ [
+ "Seitenelemente an Dokumentänderungen anpassen",
+ "Adapter les éléments de page aux modifications du document",
+ "Ajustar los elementos de página a los cambios del documento",
+ "ページ要素をドキュメントの変更に合わせて調整",
+ "根据文档更改调整页面元素",
+ ],
+ ),
+ (
+ "Apply the changes; objects follow the new page size and margins",
+ [
+ "Änderungen anwenden; Objekte folgen dem neuen Seitenformat und den Rändern",
+ "Appliquer les modifications ; les objets suivent le nouveau format et les marges",
+ "Aplicar los cambios; los objetos siguen el nuevo tamaño de página y los márgenes",
+ "変更を適用し、オブジェクトを新しいページサイズとマージンに合わせます",
+ "应用更改;对象跟随新的页面大小和边距",
+ ],
+ ),
- ("Top:", ["Oben:", "Haut :", "Superior:", "天:", "上:"]),
- ("Bottom:", ["Unten:", "Bas :", "Inferior:", "地:", "下:"]),
- ("Inside:", ["Innen:", "Intérieur :", "Interior:", "ノド:", "内:"]),
- ("Outside:", ["Außen:", "Extérieur :", "Exterior:", "小口:", "外:"]),
- ("Left:", ["Links:", "Gauche :", "Izquierda:", "左:", "左:"]),
- ("Right:", ["Rechts:", "Droite :", "Derecha:", "右:", "右:"]),
+ ("Bleed:", ["Anschnitt:", "Fond perdu :", "Sangrado:", "裁ち落とし:", "出血:"]),
+ ("Slug:", ["Infobereich:", "Ligne-bloc :", "Indicaciones:", "印刷可能領域:", "辅助信息区:"]),
];
/// Interface direction; independent of document binding and paragraph direction.
diff --cc crates/ui-egui/src/i18n/it.rs
index ea2ffd287,00328ac9f..faa39a238
--- a/crates/ui-egui/src/i18n/it.rs
+++ b/crates/ui-egui/src/i18n/it.rs
@@@ -1512,16 -1602,4 +1602,10 @@@ pub(super) const TABLE: &[(&str, &str)
("Rule Below", "Filetto sotto"),
("Tint:", "Tinta:"),
("Presentation", "Presentazione"),
+ // Document Setup
+ ("Page Size:", "Dimensioni pagina:"),
+ ("Adjust page elements to document changes", "Adatta gli elementi della pagina alle modifiche del documento"),
+ ("Apply the changes; objects follow the new page size and margins", "Applica le modifiche; gli oggetti seguono le nuove dimensioni e i margini"),
- ("Top:", "Alto:"),
- ("Bottom:", "Basso:"),
- ("Inside:", "Interno:"),
- ("Outside:", "Esterno:"),
- ("Left:", "Sinistra:"),
- ("Right:", "Destra:"),
+ ("Bleed:", "Pagina al vivo:"),
+ ("Slug:", "Indicazioni:"),
];
diff --cc docs/target-app-parity.md
index b18bea509,62ba7f08a..a7dafcb0b
--- a/docs/target-app-parity.md
+++ b/docs/target-app-parity.md
@@@ -421,8 -428,8 +428,8 @@@ It is evidence of breadth: each item ex
- View › Display Performance: Fast (grey boxes, no effects, ⌥⇧⌘Z), Typical (72 ppi proxies, ⌥⌘Z), High Quality (⌥⌘H, our default — the renderer is fast enough).
- OpenType menu (Character panel): discretionary ligatures, fractions, ordinal, swash, titling, contextual alternates, slashed zero, the four figure styles and stylistic sets 1–20; `type.openType`; mapped to IDML's OTF attributes.
- Add Anchor Point (=), Delete Anchor Point (-) and Convert Direction Point (⇧C) tools (click toggles smooth/corner, drag pulls out handles), with `path.addAnchor`, `path.deleteAnchor`, `path.convertAnchor`.
- - Gradients: the Gradient Swatch tool (G) drags a gradient's start and end across objects (Shift: 45°); the Gradient panel sets type, angle, reverse and edits stops on a ramp (drag, add, drag off to remove, location, colour). Edited gradients are unnamed swatches; `object.gradient`; the vector round-trips through IDML.
+ - Gradients: the Gradient Swatch tool (G) drags a gradient's start and end across objects (Shift: 45°); the Gradient panel sets type, angle, reverse and edits stops on a ramp (drag, add, drag off to remove, location, colour). Edited gradients are unnamed swatches; `object.gradient` (`target: stroke` for a stroke's gradient, drawn across the path's box on screen and in PDF); the vector round-trips through IDML (`GradientFill…`/`GradientStroke…`). The Gradient panel follows the Fill/Stroke proxy. A radial gradient stretches with the object's box as InDesign's does (an ellipse reaching the sides of a non-square frame, on screen and in PDF). Text takes a gradient swatch as its fill or stroke, laid across its frame's box as in InDesign (screen and PDF).
-- Document Setup (⌥⌘P): intent, number of pages, start page # (an even start begins with a left page), facing pages, size presets and orientation, bleed and slug per edge; `layout.documentSetup {}` reports the setup.
+- Document Setup (⌥⌘P), laid out like InDesign's: intent, number of pages, start page # (an even start begins with a left page), facing pages, binding, Page Size (presets keeping the orientation, width and height with arrows, orientation), margins for every page and parent page, bleed and slug per edge (each group linked or not), and Adjust Layout (objects follow the new page size and margins), all in one undo step; measures are read in the document's units, and a value that can't be read keeps the dialog open; `layout.documentSetup {}` reports the setup, margins included.
- Stroke panel: cap, join, miter limit, alignment, type, Start/End arrowheads (12 kinds, drawn on screen and in PDF; the path is shortened under pointed heads) and gap colour under dashes and dots.
- Preferences (⌘K: General, Type, Units & Increments, Grids, Guides & Pasteboard, Display Performance) backed by `prefs.set` (application) and `document.preferences` (units, increments, grids — undoable, saved with the document; right-click a ruler to pick its units, the horizontal and vertical rulers each have their own); scaling applies to content and scales stroke weights (Include Stroke Weight), and X/Y/W/H measure the stroke's outer edge (Dimensions Include Stroke Weight). Quick Apply (⌘Return) finds paragraph, character and object styles as well as commands.
- Parent item overrides: Cmd+Shift-click a parent item on a page (or Override All Parent Page Items, ⌥⇧⌘L) makes an editable local copy that hides the parent's; Remove All Local Overrides and Detach All Objects from Parent in the Pages panel menu.