Skip to content

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

Merge origin/main into codex/handle-double-click-fit

moppeeerf56273f72e93
diff --cc ROADMAP.md
index 2a6b37229,d60a6bf49..d84bf7cc7
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@@ -160,10 -438,16 +438,17 @@@ 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-12** · Double-clicking a frame handle fits the frame to its content as in InDesign (a corner fits both sides, an edge only its own). Object › Fitting › Fit Frame to Content now fits text frames to their text too, growing them for overset text; fitting leaves locked objects and objects on locked layers as they are. 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** · 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/engine/src/cmd/object.rs
index a45e71ca0,bbc0a36a1..ca32c517c
--- a/crates/engine/src/cmd/object.rs
+++ b/crates/engine/src/cmd/object.rs
@@@ -586,7 -615,7 +615,7 @@@ pub fn specs() -> Vec<CommandSpec>
"Fitting",
["Object", "Fitting"],
None,
- "{mode: fillProportionally|fitProportionally|fitContentToFrame|centerContent|fitFrameToContent, axis?: both|height|width (frame-local sides Fit Frame to Content moves; default both), ids?} — locked objects and objects on locked layers are left as they are",
- "{mode: fillProportionally (preserves aspect ratio, covers frame, clips overflow)|fitProportionally (preserves aspect ratio, shows whole image, may leave empty space)|fitContentToFrame (stretches content to frame)|centerContent (keeps current size, positions at fitting alignment)|fitFrameToContent (resizes frame to content), ids?}",
++ "{mode: fillProportionally (preserves aspect ratio, covers frame, clips overflow)|fitProportionally (preserves aspect ratio, shows whole image, may leave empty space)|fitContentToFrame (stretches content to frame)|centerContent (keeps current size, positions at fitting alignment)|fitFrameToContent (resizes frame to content), axis?: both|height|width (frame-local sides Fit Frame to Content moves; default both), ids?} — locked objects and objects on locked layers are left as they are",
has_selection,
fit
),
@@@ -3441,126 -3461,35 +3574,159 @@@ mod spread_target_tests
}
}
+#[cfg(test)]
+mod fit_text_frame_tests {
+ use super::*;
+
+ fn frame(s: &mut Session, rect: [f64; 4], text: &str) -> ItemId {
+ let id = ItemId(s.execute("frame.create", &json!({"rect": rect, "content": "text", "text": text})).unwrap()["id"].as_u64().unwrap());
+ s.execute("selection.set", &json!({"ids": [id.0]})).unwrap();
+ s.execute("type.char", &json!({"attrs": {"size": 30}})).unwrap();
+ id
+ }
+
+ fn bounds(s: &Session, id: ItemId) -> Rect {
+ s.doc().unwrap().doc.item(id).unwrap().bounds()
+ }
+
+ #[test]
+ fn fit_frame_to_content_fits_a_text_frame_to_its_text() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let id = frame(&mut s, [100.0, 100.0, 500.0, 300.0], "INDESIGN");
+ // The height only (a top or bottom handle): the width stays.
+ s.execute("object.fit", &json!({"mode": "fitFrameToContent", "axis": "height", "ids": [id.0]})).unwrap();
+ let h = bounds(&s, id);
+ assert!(h.x1 == 500.0 && h.y0 == 100.0 && h.height() > 30.0 && h.height() < 45.0, "{h:?}");
+ // Both (a corner handle, or the menu): around the line.
+ s.execute("object.fit", &json!({"mode": "fitFrameToContent", "ids": [id.0]})).unwrap();
+ let b = bounds(&s, id);
+ assert!(b.x0 == 100.0 && b.width() > 100.0 && b.width() < 250.0, "{b:?}");
+ let d = s.doc().unwrap().doc.clone();
+ let sid = d.item(id).unwrap().text_frame().unwrap().story;
+ assert!(!s.cache.get(&d, sid, None).is_overset(), "still fits");
+ }
+
+ #[test]
+ fn fit_frame_to_content_grows_a_frame_with_overset_text() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let id = frame(&mut s, [100.0, 100.0, 300.0, 140.0], "one two three four five six seven eight nine ten eleven twelve");
+ let d = s.doc().unwrap().doc.clone();
+ let sid = d.item(id).unwrap().text_frame().unwrap().story;
+ assert!(s.cache.get(&d, sid, None).is_overset());
+ s.execute("object.fit", &json!({"mode": "fitFrameToContent", "axis": "height", "ids": [id.0]})).unwrap();
+ let d = s.doc().unwrap().doc.clone();
+ assert!(!s.cache.get(&d, sid, None).is_overset(), "{:?}", bounds(&s, id));
+ assert!(bounds(&s, id).height() > 100.0);
+ assert!(s.execute("object.fit", &json!({"mode": "fitFrameToContent", "axis": "diagonal", "ids": [id.0]})).is_err());
+ }
+
+ #[test]
+ fn fitting_text_keeps_columns_and_vertical_justification() {
+ use designcraft_doc::VerticalJustification::{Bottom, Center, Justify, Top};
+ for columns in [1, 2] {
+ for justification in [Top, Bottom, Center, Justify] {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let id = frame(&mut s, [100.0, 100.0, 500.0, 500.0], "one two three four five six seven eight nine ten eleven twelve");
+ let options = &mut Arc::make_mut(&mut s.doc_mut().unwrap().doc).item_mut(id).unwrap().text_frame_mut().unwrap().options;
+ options.columns = columns;
+ options.vertical_justification = justification;
+ s.execute("object.fit", &json!({"mode": "fitFrameToContent", "axis": "height"})).unwrap();
+ let d = &s.doc().unwrap().doc;
+ let it = d.item(id).unwrap();
+ let tf = it.text_frame().unwrap();
+ let composed = s.cache.get(d, tf.story, None);
+ assert!(!composed.is_overset(), "{columns} {justification:?}");
+ assert!(it.bounds().height() < 250.0, "{columns} {justification:?}: {:?}", it.bounds());
+ assert_eq!(tf.options.vertical_justification, justification);
+ assert_eq!(tf.options.columns, columns);
+ if columns == 2 {
+ let ft = composed.frame(id).unwrap();
+ assert!(ft.lines.iter().any(|l| l.column == 1), "both columns stay in use: {ft:?}");
+ }
+ }
+ }
+ }
+
+ #[test]
+ fn graphic_fitting_obeys_each_axis_and_locked_text_and_graphics_stay_put() {
+ for graphic in [false, true] {
+ for lock_layer in [false, true] {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let id = frame(&mut s, [100.0, 100.0, 500.0, 300.0], "Fit me");
+ if graphic {
+ let png = designcraft_render::Rendered { width: 40, height: 20, pixels: vec![200; 40 * 20 * 4] }.to_png();
+ s.execute("file.place", &json!({"base64": super::super::file::base64_encode(&png), "name": "test.png", "frame": id.0})).unwrap();
+ let it = Arc::make_mut(&mut s.doc_mut().unwrap().doc).item_mut(id).unwrap();
+ let Content::Graphic(g) = &mut it.content else { panic!("graphic") };
+ g.xf = Affine::translate((80.0, 90.0)) * Affine::scale(3.0);
+ let original = it.inner_bounds();
+ s.execute("object.fit", &json!({"mode": "fitFrameToContent", "axis": "width", "ids": [id.0]})).unwrap();
+ let fitted = s.doc().unwrap().doc.item(id).unwrap().inner_bounds();
+ assert_eq!(fitted, Rect::new(80.0, original.y0, 200.0, original.y1));
+ Arc::make_mut(&mut s.doc_mut().unwrap().doc).item_mut(id).unwrap().path = shapes::rectangle(original);
+ s.execute("object.fit", &json!({"mode": "fitFrameToContent", "axis": "height", "ids": [id.0]})).unwrap();
+ assert_eq!(s.doc().unwrap().doc.item(id).unwrap().inner_bounds(), Rect::new(original.x0, 90.0, original.x1, 150.0));
+ Arc::make_mut(&mut s.doc_mut().unwrap().doc).item_mut(id).unwrap().path = shapes::rectangle(original);
+ }
+ let before = bounds(&s, id);
+ if lock_layer {
+ let layer = s.doc().unwrap().doc.item(id).unwrap().layer;
+ Arc::make_mut(&mut s.doc_mut().unwrap().doc).layer_mut(layer).unwrap().locked = true;
+ } else {
+ Arc::make_mut(&mut s.doc_mut().unwrap().doc).item_mut(id).unwrap().locked = true;
+ }
+ s.execute("object.fit", &json!({"mode": "fitFrameToContent", "ids": [id.0]})).unwrap();
+ assert_eq!(bounds(&s, id), before, "graphic={graphic}, layer={lock_layer}");
+ }
+ }
+ }
+
+ #[test]
+ fn an_unfittable_frame_returns_an_error_without_changing_any_target() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let a = frame(&mut s, [100.0, 100.0, 500.0, 300.0], "Fits");
+ let b = frame(&mut s, [100.0, 400.0, 500.0, 600.0], "Cannot fit");
+ Arc::make_mut(&mut s.doc_mut().unwrap().doc).item_mut(b).unwrap().text_frame_mut().unwrap().options.first_baseline_min = 30_000.0;
+ let before = [bounds(&s, a), bounds(&s, b)];
+ assert!(s.execute("object.fit", &json!({"mode": "fitFrameToContent", "ids": [a.0, b.0]})).is_err());
+ assert_eq!([bounds(&s, a), bounds(&s, b)], before);
+ }
+}
++
+ #[cfg(test)]
+ mod fill_tint_tests {
+ use super::*;
+
+ #[test]
+ fn a_tint_alone_keeps_each_objects_own_swatch() {
+ let mut s = Session::new();
+ s.execute("file.new", &json!({})).unwrap();
+ let a = s.execute("frame.create", &json!({"rect": [36, 36, 100, 100]})).unwrap()["id"].as_u64().unwrap();
+ let b = s.execute("frame.create", &json!({"rect": [136, 36, 200, 100]})).unwrap()["id"].as_u64().unwrap();
+ s.execute("object.fill", &json!({"ids": [a], "swatch": "C=100 M=0 Y=0 K=0"})).unwrap();
+ s.execute("object.fill", &json!({"ids": [b], "swatch": "C=0 M=100 Y=0 K=0"})).unwrap();
+ s.execute("object.fill", &json!({"ids": [a, b], "tint": 0.4})).unwrap();
+ let fill_of = |s: &Session, id: u64| s.doc().unwrap().doc.item(ItemId(id)).unwrap().fill.clone();
+ assert_eq!((fill_of(&s, a).swatch.as_str(), fill_of(&s, a).tint), ("C=100 M=0 Y=0 K=0", 0.4));
+ assert_eq!((fill_of(&s, b).swatch.as_str(), fill_of(&s, b).tint), ("C=0 M=100 Y=0 K=0", 0.4));
+ // A swatch without a tint is at 100 %, as before.
+ s.execute("object.fill", &json!({"ids": [a], "swatch": "[Black]"})).unwrap();
+ assert_eq!(fill_of(&s, a).tint, 1.0);
+ // Neither, or a tint out of range: refused.
+ assert!(s.execute("object.fill", &json!({"ids": [a]})).is_err());
+ assert!(s.execute("object.fill", &json!({"ids": [a], "tint": 2})).is_err());
+ assert!(s.execute("object.fill", &json!({"ids": [a], "tint": "x"})).is_err());
+ // A stroke tint alone: stroked objects take it, an object without a stroke keeps none.
+ s.execute("object.stroke", &json!({"ids": [a], "swatch": "C=100 M=0 Y=0 K=0", "weight": 2})).unwrap();
+ s.execute("object.stroke", &json!({"ids": [b], "swatch": "[None]"})).unwrap();
+ s.execute("object.stroke", &json!({"ids": [a, b], "tint": 0.5})).unwrap();
+ let stroke_of = |s: &Session, id: u64| s.doc().unwrap().doc.item(ItemId(id)).unwrap().stroke.clone();
+ assert_eq!((stroke_of(&s, a).swatch.as_str(), stroke_of(&s, a).tint, stroke_of(&s, a).weight), ("C=100 M=0 Y=0 K=0", 0.5, 2.0));
+ assert!(stroke_of(&s, b).is_none());
+ }
+ }
diff --cc crates/tools/src/tests.rs
index 12be49fde,aacfb8d3f..70cc854fa
--- a/crates/tools/src/tests.rs
+++ b/crates/tools/src/tests.rs
@@@ -1160,44 -1214,103 +1214,145 @@@ fn eyedropper_samples_a_placed_image_an
assert_eq!(a, vec![Action::Exec("object.matchAttributes".into(), serde_json::json!({"from": photo.0}))]);
}
+ #[test]
+ fn eyedropper_ignores_inactive_states_of_a_multi_state_object() {
+ use designcraft_doc::{Asset, AssetId, Content, Graphic};
+ let mut d = Document::new(&NewDocument::default());
+ let lid = d.default_layer();
+ d.assets.insert(
+ AssetId(1),
+ std::sync::Arc::new(Asset {
+ id: AssetId(1),
+ name: "photo.png".into(),
+ mime: "image/png".into(),
+ link: None,
+ data: std::sync::Arc::new(vec![]),
+ pixels: Some((100, 100)),
+ page: 0,
+ }),
+ );
+ let area = Rect::new(100.0, 100.0, 200.0, 200.0);
+ let raster = {
+ let mut it = Item::new(ItemId(d.alloc()), lid, Shape::Rectangle, shapes::rectangle(area));
+ it.content = Content::Graphic(Graphic {
+ asset: AssetId(1),
+ size: (100.0, 100.0),
+ xf: designcraft_geom::Affine::translate((0.0, 0.0)),
+ auto_fit: Default::default(),
+ fit_align: 4,
+ crop: [0.0; 4],
+ });
+ it
+ };
+ let mut vector = Item::new(ItemId(d.alloc()), lid, Shape::Rectangle, shapes::rectangle(area));
+ vector.fill.swatch = "[Black]".into();
+ let target = add_rect(&mut d, Rect::new(400.0, 100.0, 450.0, 150.0));
+ let s = Selection { items: vec![target], ..Default::default() };
+ let sample = Action::Exec("color.sample".into(), serde_json::json!({"at": [120.0, 130.0], "spread": {"kind": "doc", "index": 0}}));
+ // Children [vector, raster] with the raster on top: it samples only while it is the active state.
+ for (active, samples) in [(1, true), (0, false)] {
+ let mut group = Item::new(ItemId(d.alloc()), lid, Shape::Rectangle, shapes::rectangle(area));
+ group.content = Content::Group { items: vec![std::sync::Arc::new(vector.clone()), std::sync::Arc::new(raster.clone())] };
+ group.states = vec!["a".into(), "b".into()];
+ group.active_state = active;
+ let mut d2 = d.clone();
+ d2.insert_item(SpreadRef::Doc(0), group, None).unwrap();
+ let (c, l) = (Cache::new(), CanvasLayout::new(&d2, false));
+ let off = l.xf(SpreadRef::Doc(0)).translation();
+ let cx = ctx(&d2, &s, &c, &l);
+ let a = create("eyedropper").pointer(&cx, &PointerEvent::new(PointerKind::Down, 120.0 + off.x, 130.0 + off.y));
+ assert_eq!(a.contains(&sample), samples, "active state {active}: {a:?}");
+ }
+ }
+
+ #[test]
+ fn pen_cursor_shows_add_delete_and_close() {
+ let mut d = Document::new(&NewDocument::default());
+ let lid = d.default_layer();
+ let (fid, _) = d.add_text_frame(SpreadRef::Doc(0), Rect::new(100.0, 100.0, 200.0, 200.0), lid, "", ParaFormat::default()).unwrap();
+ let (c, l) = (Cache::new(), CanvasLayout::new(&d, false));
+ let selected = Selection::items(vec![fid]);
+ let none = Selection::default();
+ let off = l.xf(SpreadRef::Doc(0)).translation();
+ let at = |x: f64, y: f64| Point::new(x + off.x, y + off.y);
+ let mut t = create("pen");
+ let m = Mods::default();
+
+ let cx = ctx(&d, &selected, &c, &l);
+ assert_eq!(t.cursor(&cx, at(200.0, 100.0), m), Cursor::PenDelete, "on a selected path's anchor");
+ assert_eq!(t.cursor(&cx, at(150.0, 101.0), m), Cursor::PenAdd, "on a selected path's outline");
+ assert_eq!(t.cursor(&cx, at(150.0, 150.0), m), Cursor::Pen, "inside, away from the outline");
+ let click = |t: &mut Box<dyn Tool>, cx: &ToolContext, p: Point| {
+ let down = t.pointer(cx, &PointerEvent::new(PointerKind::Down, p.x, p.y));
+ let up = t.pointer(cx, &PointerEvent::new(PointerKind::Up, p.x, p.y));
+ (down, up)
+ };
+ let (down, up) = click(&mut t, &cx, at(200.0, 100.0));
+ assert_eq!(down, vec![Action::Exec("path.deleteAnchor".into(), serde_json::json!({"id": fid.0, "subpath": 0, "anchor": 1}))]);
+ assert!(up.is_empty() && !t.busy(), "deleting starts no path");
+ let (down, _) = click(&mut t, &cx, at(150.0, 101.0));
+ assert!(matches!(&down[..], [Action::Exec(cmd, p)] if cmd == "path.addAnchor" && p["id"] == fid.0), "{down:?}");
+
+ // Unselected paths are drawn over; the first anchor of the path being drawn closes it.
+ let cx = ctx(&d, &none, &c, &l);
+ assert_eq!(t.cursor(&cx, at(200.0, 100.0), m), Cursor::Pen, "unselected path");
+ click(&mut t, &cx, at(300.0, 300.0));
+ assert_eq!(t.cursor(&cx, at(300.0, 300.0), m), Cursor::Pen, "one anchor cannot close yet");
+ click(&mut t, &cx, at(400.0, 300.0));
+ assert_eq!(t.cursor(&cx, at(301.0, 301.0), m), Cursor::PenClose, "on the first anchor");
+ assert_eq!(t.cursor(&cx, at(350.0, 350.0), m), Cursor::Pen, "elsewhere while drawing");
+ }
+
+ #[test]
+ fn anchor_tools_show_pen_state_cursors() {
+ let d = Document::new(&NewDocument::default());
+ let (s, c, l) = (Selection::default(), Cache::new(), CanvasLayout::new(&d, false));
+ let cx = ctx(&d, &s, &c, &l);
+ let p = Point::new(10.0, 10.0);
+ let cursor = |id: &str| create(id).cursor(&cx, p, Mods::default());
+ assert_eq!(cursor("addAnchor"), Cursor::PenAdd);
+ assert_eq!(cursor("deleteAnchor"), Cursor::PenDelete);
+ assert_eq!(cursor("convertDirection"), Cursor::PenConvert);
+ }
++
+#[test]
+fn double_clicking_a_handle_fits_the_frame_to_its_content_along_that_side() {
+ let mut d = Document::new(&NewDocument::default());
+ let id = add_rect(&mut d, Rect::new(100.0, 100.0, 300.0, 200.0));
+ let s = Selection { items: vec![id], ..Default::default() };
+ let (c, l) = (Cache::new(), CanvasLayout::new(&d, false));
+ let off = l.xf(SpreadRef::Doc(0)).translation();
+ let cx = ctx(&d, &s, &c, &l);
+ let mut t = create("selection");
+ for ((x, y), axis) in [((300.0, 200.0), "both"), ((200.0, 200.0), "height"), ((300.0, 150.0), "width")] {
+ let a = t.pointer(&cx, &PointerEvent::new(PointerKind::DoubleClick, x + off.x, y + off.y));
+ assert_eq!(a, vec![Action::Exec("object.fit".into(), serde_json::json!({"mode": "fitFrameToContent", "axis": axis}))], "{axis}");
+ }
+}
+
+#[test]
+fn fitting_handle_axes_follow_spread_and_frame_rotation() {
+ for spread_turn in 0..4 {
+ for frame_turn in 0..4 {
+ let mut d = Document::new(&NewDocument::default());
+ let id = add_rect(&mut d, Rect::new(100.0, 100.0, 300.0, 200.0));
+ d.item_mut(id).unwrap().xf = designcraft_geom::Affine::rotate(f64::from(frame_turn) * std::f64::consts::FRAC_PI_2);
+ Arc::make_mut(&mut d.spreads[0]).pages[0].view_rotation = spread_turn;
+ let s = Selection { items: vec![id], ..Default::default() };
+ let (c, l) = (Cache::new(), CanvasLayout::new(&d, false));
+ let cx = ctx(&d, &s, &c, &l);
+ let b = cx.selection_bounds().unwrap();
+ let mut t = create("selection");
+ let swapped = (spread_turn + frame_turn) % 2 == 1;
+ for (index, axis) in [(1, if swapped { "width" } else { "height" }), (3, if swapped { "height" } else { "width" }), (4, "both")] {
+ let p = select::handles(b)[index];
+ let a = t.pointer(&cx, &PointerEvent::new(PointerKind::DoubleClick, p.x, p.y));
+ assert_eq!(
+ a,
+ vec![Action::Exec("object.fit".into(), serde_json::json!({"mode": "fitFrameToContent", "axis": axis}))],
+ "spread={spread_turn}, frame={frame_turn}, handle={index}"
+ );
+ }
+ }
+ }
+}
diff --cc crates/ui-egui/src/canvas.rs
index e9a3fdfb3,40b146f56..1c8663c8c
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@@ -1909,49 -2376,38 +2376,81 @@@ mod tests
(s.horizontal_units, s.vertical_units)
}
+ /// A viewport wider than the GPU's largest texture: the canvas texture is sampled down, and an
+ /// edit repaints it whole. A region repainted in view pixels would land in the wrong place,
+ /// or outside the texture (a wgpu validation error). A view that fits is still patched.
+ #[test]
+ fn an_edit_repaints_a_canvas_texture_sampled_down_to_the_gpu_limit_whole() {
+ for (width, sampled_down) in [(1440.0, false), (2600.0, true)] {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ let frame = app.run("frame.create", json!({"rect": [72, 72, 400, 300], "content": "text", "text": "Text"})).unwrap();
+ let mut h = Harness::builder().with_size(vec2(width, 900.0)).build_ui_state(
+ |ui, app: &mut DesignApp| {
+ let ctx = ui.ctx().clone();
+ app.logic(&ctx);
+ app.ui(ui);
+ },
+ app,
+ );
+ h.run_steps(6);
+ let limit = h.ctx.input(|i| i.max_texture_side);
+ let size = h.state().canvas.texture.as_ref().map(|t| t.size()).unwrap();
+ assert!(size[0] <= limit && size[1] <= limit, "{size:?}");
+ let shown = h.state().canvas.shown.unwrap().size;
+ assert_eq!(shown.0 > limit as f32, sampled_down, "view {shown:?}, limit {limit}");
+ let patches = h.state().canvas.patches;
+ // A small edit: one more character in the frame.
+ h.state_mut().run("text.insert", json!({"story": frame["story"], "at": 4, "text": "s"})).unwrap();
+ h.run_steps(6);
+ assert_eq!(h.state().canvas.patches == patches, sampled_down, "width {width}");
+ assert_eq!(h.state().canvas.texture.as_ref().map(|t| t.size()), Some(size));
+ }
+ }
+
+ #[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);
+ }
+
#[test]
fn selected_merged_owners_paint_the_same_row_and_column_targets() {
for column in [true, false] {