DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge PR #1416: Direct Selection: select anchor points with a marquee across paths and move them together
aiongg3b79317e0338
diff --cc ROADMAP.mdindex 52bfb0f3b,19b32ebaf..1395acef5--- a/ROADMAP.md+++ b/ROADMAP.md@@@ -460,36 -443,8 +460,38 @@@ Newest first- **2026-10-16** · Lock Guides and Lock Column Guides are commands in View ▸ Grids & Guides (`view.lockGuides`, ⌥⌘;, and `view.lockColumnGuides`), so the control channel and MCP reach them. Lock Column Guides is an undo step, is saved with the document, on in new ones, and read from and written to IDML's `ColumnGuideLocked`, which export always wrote as locked (#1096). No readiness percentage change.- **2026-10-16** · IDML: a page keeps column guides that were dragged off centre (InDesign's Custom columns). They were divided evenly on import, so the gutter sprang back to the middle; the imported positions now place the columns, with the canvas guides, snapping and text placement following them, and they are written back on export. Layout › Margins and Columns re-divides them evenly when the count or gutter changes, as InDesign's does. No readiness percentage change.- **2026-10-16** · IDML: custom column positions are checked before they are used (#1096). A set must give two edges per column, ascending from the left margin to the right one; any other (a wrong count, unsorted or non-numeric values, a list longer than 216 columns allow, or positions left behind by a margin or page-size change) is the even split, in the canvas, on import and on export, instead of columns drawn outside the margins. No readiness percentage change.+- **2026-10-21** · Paragraph Border and Paragraph Shading link their four sides as InDesign's: the stroke weights, offsets and corners have the "Make all settings the same" link, on when the four are the same, so a side typed in sets all four; with the link off a side is set alone (a border with only a thick left side). Found in the Learn Skills Daily course, chapter 40. No readiness percentage change.+- **2026-10-21** · Paragraph rules have InDesign's Type (solid, thick/thin stripes, dashed, dotted, straight hash, wavy, or a stroke style of the document), Gap Color and Gap Tint, and Keep In Frame (rule above); the Paragraph Rules page is laid out as InDesign's (Weight and Type, Color and Tint, Gap Color and Gap Tint, Width and Offset, Left and Right Indent). IDML reads and writes them (`RuleAboveType`, `RuleBelowGapColor`, `KeepRuleAboveInFrame`…). Found in the Learn Skills Daily course, chapter 20. No readiness percentage change.+- **2026-10-21** · New Character Style with text selected starts from what the text has of its own over its paragraph style, as InDesign's ("[None] + Bold + color"), and Apply Style to Selection gives the text the new style, with no override left. A new style's dialog is titled New Paragraph Style / New Character Style. `type.selectionAttrs` reports the text's own character attributes (`ownChars`). Found in the Learn Skills Daily course, chapter 22. No readiness percentage change.+- **2026-10-21** · New Paragraph Style with text selected starts from it, as InDesign's (Based On [No Paragraph Style], every setting of the text that differs) and Apply Style to Selection gives the paragraph the new style; General has Next Style and Reset To Base; Basic Character Formats is in two columns (Size | Leading, Kerning | Tracking, Case | Position). `style.paragraph.edit` honours `nextStyle` (it was ignored) and takes `resetToBase`. Found in the Learn Skills Daily course, chapter 20. No readiness percentage change.+- **2026-10-21** · Find/Change has InDesign's Change Format. Specify Attributes opens Change Format Settings: Style Options (the character and paragraph style to apply, [Any Style] for none), then Basic and Advanced Character Formats, Character Color, OpenType Features, Underline and Strikethrough Options. The box shows the format ("Character Style: eggs"), and Change All gives it to the changed text. With a Change Format and nothing in Change to, the found text stays and is only formatted, as InDesign's (an ⓘ beside Change to says so). `find.change` takes `charStyle` and `paraStyle`. Found in the Learn Skills Daily course, chapter 22. No readiness percentage change.+- **2026-10-21** · Preferences › Interface follows InDesign's: Appearance has a Color Theme swatch per interface theme (a click shows it at once, Cancel goes back) and Panels sets the Tools panel to a single or double column; UI Size moves to a UI Scaling section of its own. Interface held only UI Size, and the theme could be changed only from the Window menu. Found in the Learn Skills Daily course, chapter 26. No readiness percentage change.+- **2026-10-21** · Preferences › File Handling shows Number of Recent Items to Display as a whole number ("20"; it read "20.0"). Found in the Learn Skills Daily course, chapter 26. No readiness percentage change.+- **2026-10-21** · Insert Pages… opens InDesign's dialog: Pages, Insert (After Page, Before Page, At Start of Document, At End of Document) with the page by name, and Parent ([None] or a parent), set to the page in view and its parent. It was a form asking for a page index and a parent id, and pages could not go before the first page; `layout.pages.insert` takes `before` (0: at the start). Found in the Learn Skills Daily course, chapter 25. No readiness percentage change.+- **2026-10-21** · Spelling (Check Spelling and Dynamic Spelling) no longer flags everyday words the bundled hyphenation word list lacks: "we", "us", "if", titles such as "Mr", and words such as email, online, website, database, desktop and download, with their plurals and other forms. Contractions typed with a typographer's apostrophe (don’t, we’re), which Use Typographer's Quotes produces by default, count like their straight-apostrophe forms. Dynamic Spelling used to underline most words of an ordinary sentence. Found in the Learn Skills Daily course, chapter 26. No readiness percentage change.+- **2026-10-21** · While a parent is shown, the status bar's page box and Properties › Page name it ("A-Parent") instead of page 1, as InDesign's; their lists have the parents after the pages, and choosing one shows that parent (a page leaves the parents). Found in the Learn Skills Daily course, chapter 25. No readiness percentage change.+- **2026-10-21** · Effects dialog: the Angle field of the shadows, Bevel and Emboss, Satin and Gradient Feather has InDesign's dial beside it, its radius pointing where the light comes from; a click or drag on it sets the angle. Found in the Learn Skills Daily course, chapter 14. No readiness percentage change.+- **2026-10-21** · A double-click on a Fill or Stroke chip of Properties › Appearance opens the Color Picker with its colour, as in InDesign (a click still opens the swatches); for selected text, its own chips open it for the text. Found in the Learn Skills Daily course, chapter 23. No readiness percentage change.+- **2026-10-20** · Properties › Appearance: with several text frames selected, the Fill and Stroke popups offer Apply To Frame or Text, as with one frame, so their text can be coloured at once, as in InDesign. No readiness percentage change.+- **2026-10-20** · Properties › Appearance: the arrow beside Opacity opens a slider under the field, as in InDesign, instead of the Effects panel; a drag shows the opacity live and is one undo step (the Opacity link still opens Effects). No readiness percentage change.+- **2026-10-20** · Properties › Frame Fitting has InDesign's Auto-Fit checkbox and Options button (Frame Fitting Options); the app's checkboxes are now named and ticked-or-not for screen readers. No readiness percentage change.+- **2026-10-20** · Properties › Text Wrap shows the four wrap offsets under the wrap buttons, with the link that makes them the same, as InDesign's Properties panel does (greyed with no wrap). No readiness percentage change.+- **2026-10-21** · Properties › Bullets and Numbering › Options opens the Bullets and Numbering dialog for the selected paragraphs, as InDesign's, instead of the Paragraph panel. Found in the Learn Skills Daily course, chapter 21. No readiness percentage change.+- **2026-10-20** · Properties › Appearance: the corner shape list shows each shape's glyph beside its name, drawn as InDesign draws them (Fancy has its own glyph now), and the stroke type list shows each type's line; both dropdowns are named for screen readers. No readiness percentage change.+- **2026-10-21** · Properties › Align: the Align To button shows what the objects align to, one glyph each for the selection, the key object, the margins, the page and the spread, as InDesign's. Found in the Learn Skills Daily course, chapter 12. No readiness percentage change.+- **2026-10-20** · Object › Corner Options opens a Corner Options dialog laid out as InDesign's: each corner's size and shape, the link button that makes all four the same, and Preview. The Corner link in Properties › Appearance opens it too (it opened a Rectangle size dialog). No readiness percentage change.+- **2026-10-20** · The Object menu is in InDesign's order and groups; Paths has Join, Open Path and Close Path (Convert Shape lists only shapes, as InDesign's does) and a Convert Point submenu (Plain, Corner, Smooth, Symmetrical) is added. No readiness percentage change.+- **2026-10-20** · Layout › Create Guides puts its guides on both pages of the spread in view, as InDesign does; "This page" in Apply to narrows them to one page. No readiness percentage change.+- **2026-10-21** · Object › Fitting › Clear Frame Fitting Options (`object.clearFittingOptions`): the frames' auto-fit, crop amounts and reference point go back to their defaults, and the picture stays where it is. The Fitting submenu is grouped as InDesign's. Found in the Learn Skills Daily course, chapter 11. No readiness percentage change.+- **2026-10-21** · Swatches panel rows show InDesign's columns, drawn in code: a crossed pencil on the swatches that can't be edited ([None], [Registration], [Black]), the colour type (process or spot) and the colour mode (CMYK, RGB, Gray, or [None]'s and [Registration]'s own glyphs), in place of a lock and "CMYK" text. Tint reads 100 with nothing selected. No readiness percentage change.+- **2026-10-21** · With a gradient fill or stroke, the Color panel shows the stop selected in the Gradient panel (the stop before a selected midpoint) with its values, and its C/M/Y/K or R/G/B sliders and spectrum colour that stop, keeping the others, as in InDesign. It showed "[None] — choose a colour on the ramp", and a spectrum click replaced the whole gradient with a flat colour. Found in the Learn Skills Daily course, chapter 24. No readiness percentage change.+- **2026-10-20** · A new document's Swatches panel lists InDesign's defaults: [None], [Registration], [Paper], [Black] and six process colours (C=100, M=100, Y=100, C=15 M=100 Y=100, C=75 M=5 Y=100, C=100 M=90 Y=10); the extra M=100 Y=100, C=100 Y=100 and C=100 M=100 swatches are gone. No readiness percentage change.+- **2026-10-21** · The readout beside the cursor while drawing or measuring ("W: 3.13 cm") is InDesign's light grey box with white text, measured from the tutorials' frames; High Contrast keeps it black. It was a dark translucent box. No readiness percentage change.+- **2026-10-20** · Drawing a frame or shape shows its width and height in the document's ruler units, to two decimals and on two lines ("W: 6.08 cm", "H: 6.08 cm"), as InDesign does; it was always whole points. No readiness percentage change.+- **2026-10-20** · Type tool: a drag that starts in an empty frame draws a new text frame over it, as in InDesign; a click still turns the frame into a text frame. No readiness percentage change.+- **2026-10-20** · Measures in centimetres show four decimals, as InDesign's fields do (a 1p gutter reads 0.4233 cm, not 0.423 cm). No readiness percentage change.+ - **2026-10-14** · The Direct Selection tool pressed on a corner or anchor of an object that isn't selected selects it and pulls just that point, as in InDesign (it moved the whole object). No readiness percentage change.+ - **2026-10-20** · Direct Selection selects anchor points: a marquee selects the points inside it on every path it reaches, a click selects one point and Shift+click adds or removes one, selected points show solid, and dragging one (Shift: at 45° steps) or pressing the arrow keys moves them all in one step (`selection.set {anchors}`, `path.moveAnchors {points}`). No readiness percentage change.- **2026-10-21** · Properties › Character and Paragraph: ••• (More Options) expands the section in place, as InDesign's: Character adds vertical and horizontal scale, baseline shift, skew, language and OpenType, and All Caps, Small Caps, Superscript, Subscript, Underline and Strikethrough; Paragraph adds the left, right, first line and last line indents, space before and after, the drop cap's lines and characters, Align to Baseline Grid and Hyphenate. It used to open the Character or Paragraph panel; the language field moved under ••• as in InDesign. Found in the Learn Skills Daily course, chapter 16. No readiness percentage change.- **2026-10-21** · The text Control panel has InDesign's two modes: A (Character Formatting Controls: font and style, size and leading, All Caps/Superscript/Underline and Small Caps/Subscript/Strikethrough, kerning and tracking, vertical and horizontal scale, baseline shift and skew, character style and language) and ¶ (Paragraph Formatting Controls: the nine alignments, left/first line and right/last line indents, space before and after, the drop cap's lines and characters, paragraph style, Hyphenate and Align to Baseline Grid). It used to show a fixed mix of both. Found in the Learn Skills Daily course, chapter 16. No readiness percentage change.- **2026-10-20** · With the Type tool, the Control panel's font size, leading and tracking fields have a spinner and a list of common values, as in InDesign (auto leading in parentheses). No readiness percentage change.diff --cc crates/engine/src/tests.rsindex a72561f18,bc3138627..1b69fd773--- a/crates/engine/src/tests.rs+++ b/crates/engine/src/tests.rs@@@ -1664,45 -1661,69 +1664,108 @@@ fn a_line_fits_when_its_baseline_does(assert!(overset(&mut s, 50.0), "a baseline below the frame still oversets the line");}+/// Reset To Base with a new Based On: a partial rule edit resolves over the new parent, not the+/// old one.+#[test]+fn reset_to_base_with_a_new_parent_resolves_rule_edits_over_it() {+ let mut s = session();+ let rule = |weight: f64, offset: f64| json!({"on": true, "weight": weight, "color": "[Black]", "offset": offset});+ s.execute("style.paragraph.create", &json!({"name": "Old", "para": {"ruleBelow": rule(3.0, 1.0)}})).unwrap();+ s.execute("style.paragraph.create", &json!({"name": "New", "para": {"ruleBelow": rule(1.0, 9.0)}})).unwrap();+ s.execute("style.paragraph.create", &json!({"name": "Child", "basedOn": "Old"})).unwrap();+ s.execute("style.paragraph.edit", &json!({"name": "Child", "resetToBase": true, "basedOn": "New", "para": {"ruleBelow": {"weight": 2}}}))+ .unwrap();+ let r = s.doc().unwrap().doc.styles.resolve_para_style("Child").0.rule_below;+ assert_eq!((r.weight, r.offset), (2.0, 9.0), "the offset is the new parent's");+}++/// Paragraph style references are checked: a Based On or Next Style that names no style, or+/// that isn't a name or null, is refused and changes nothing.+#[test]+fn paragraph_style_references_must_name_styles() {+ let mut s = session();+ s.execute("style.paragraph.create", &json!({"name": "Body"})).unwrap();+ assert!(s.execute("style.paragraph.create", &json!({"name": "Lost", "nextStyle": "Nowhere"})).is_err());+ assert!(s.doc().unwrap().doc.styles.para("Lost").is_none());+ // On creation too, a reference that isn't a name or null is refused, not dropped.+ for p in [json!({"name": "Lost", "nextStyle": true}), json!({"name": "Lost", "basedOn": 3})] {+ assert!(s.execute("style.paragraph.create", &p).is_err(), "{p}");+ assert!(s.doc().unwrap().doc.styles.para("Lost").is_none(), "{p}");+ }+ assert!(s.execute("style.character.create", &json!({"name": "Lost", "basedOn": ["Body"]})).is_err());+ assert!(s.doc().unwrap().doc.styles.char_style("Lost").is_none());+ s.execute("style.paragraph.create", &json!({"name": "Self", "nextStyle": "Self"})).unwrap();+ let before = s.doc().unwrap().doc.clone();+ for p in [json!({"name": "Body", "basedOn": "Nowhere"}), json!({"name": "Body", "basedOn": 3}), json!({"name": "Body", "nextStyle": true})] {+ assert!(s.execute("style.paragraph.edit", &p).is_err(), "{p}");+ }+ assert!(std::sync::Arc::ptr_eq(&before, &s.doc().unwrap().doc), "nothing changed");+ s.execute("style.paragraph.edit", &json!({"name": "Body", "basedOn": null, "nextStyle": "Self"})).unwrap();+}++ /// Direct Selection: a marquee over the top edges of two frames selects their top points, and a+ /// drag on one of them slants both frames in one undo step (InDesign's way to make a row of+ /// parallelograms).+ #[test]+ fn direct_selection_moves_the_points_of_several_frames_at_once() {+ use designcraft_tools::{Mods, PointerEvent, PointerKind};+ let mut s = session();+ let v = ViewInfo::at_zoom(1.0);+ let a = s.execute("frame.create", &json!({"rect": [100, 300, 200, 400]})).unwrap()["id"].as_u64().unwrap();+ let b = s.execute("frame.create", &json!({"rect": [200, 300, 300, 400]})).unwrap()["id"].as_u64().unwrap();+ s.execute("selection.set", &json!({"ids": []})).unwrap();+ s.set_tool("directSelection");+ s.pointer(&PointerEvent::new(PointerKind::Down, 80.0, 280.0), v).unwrap();+ s.pointer(&PointerEvent::new(PointerKind::Drag, 320.0, 320.0), v).unwrap();+ s.pointer(&PointerEvent::new(PointerKind::Up, 320.0, 320.0), v).unwrap();+ let sel = s.doc().unwrap().selection.clone();+ assert_eq!(sel.anchors.len(), 4, "{:?}", sel.anchors);+ assert!(sel.items.contains(&designcraft_doc::ItemId(a)) && sel.items.contains(&designcraft_doc::ItemId(b)));+ let shift = Mods { shift: true, ..Default::default() };+ s.pointer(&PointerEvent::new(PointerKind::Down, 100.0, 300.0), v).unwrap();+ s.pointer(&PointerEvent::new(PointerKind::Drag, 136.0, 302.0).with_mods(shift), v).unwrap();+ s.pointer(&PointerEvent::new(PointerKind::Up, 136.0, 302.0).with_mods(shift), v).unwrap();+ let corners = |s: &Session, id: u64| -> Vec<(f64, f64)> {+ let st = s.doc().unwrap();+ let it = st.doc.item(designcraft_doc::ItemId(id)).unwrap();+ it.path.subpaths[0].anchors.iter().map(|an| ((it.xf * an.p).x.round(), (it.xf * an.p).y.round())).collect()+ };+ // Both frames: top points 36 pt to the right, bottom points where they were.+ assert_eq!(corners(&s, a), vec![(136.0, 300.0), (236.0, 300.0), (200.0, 400.0), (100.0, 400.0)]);+ assert_eq!(corners(&s, b), vec![(236.0, 300.0), (336.0, 300.0), (300.0, 400.0), (200.0, 400.0)]);+ s.execute("edit.undo", &json!({})).unwrap();+ assert_eq!(corners(&s, a), vec![(100.0, 300.0), (200.0, 300.0), (200.0, 400.0), (100.0, 400.0)]);+ assert_eq!(corners(&s, b), vec![(200.0, 300.0), (300.0, 300.0), (300.0, 400.0), (200.0, 400.0)]);+ }++ #[test]+ fn selected_points_follow_their_path() {+ let mut s = session();+ let a = s.execute("frame.create", &json!({"rect": [100, 300, 200, 400]})).unwrap()["id"].as_u64().unwrap();+ let b = s.execute("frame.create", &json!({"rect": [200, 300, 300, 400]})).unwrap()["id"].as_u64().unwrap();+ s.execute("selection.set", &json!({"anchors": [[a, 0, 1], [b, 0, 2]]})).unwrap();+ // Shift-clicking a frame off the selection drops its points too.+ s.execute("selection.toggle", &json!({"id": a})).unwrap();+ let id = |n| designcraft_doc::ItemId(n);+ assert_eq!(s.doc().unwrap().selection.anchors, vec![(id(b), 0, 2)]);+ // A point added before the first one: the selected point keeps pointing at the same anchor.+ let l = s.execute("path.create", &json!({"anchors": [{"p": [100, 100]}, {"p": [200, 100]}, {"p": [300, 150]}]})).unwrap()["id"].as_u64().unwrap();+ s.execute("selection.set", &json!({"anchors": [[l, 0, 1]]})).unwrap();+ s.execute("path.appendAnchor", &json!({"id": l, "anchor": {"p": [50, 120]}, "at": "start"})).unwrap();+ let st = s.doc().unwrap();+ let (_, si, ai) = st.selection.anchors[0];+ let it = st.doc.item(id(l)).unwrap();+ assert_eq!((it.xf * it.path.subpaths[si].anchors[ai].p).round(), designcraft_geom::Point::new(200.0, 100.0));+ // `points` that isn't a list is refused, even with an `id` beside it.+ for bad in [json!("x"), json!({"0": 1}), json!(5)] {+ assert!(s.execute("path.moveAnchors", &json!({"points": bad, "id": l, "anchors": [[0, 0]], "dx": 5})).is_err(), "points {bad}");+ }+ for bad in [json!(3), json!(-1), json!("0")] {+ assert!(s.execute("path.appendAnchor", &json!({"id": l, "anchor": {"p": [0, 0]}, "subpath": bad})).is_err(), "subpath {bad}");+ }+ assert_eq!(s.doc().unwrap().doc.item(id(l)).unwrap().path.subpaths[0].anchors.len(), 4, "nothing appended");+ }+#[test]fn direct_selection_pulls_one_corner_of_an_unselected_frame() {// Chris Nielsen's "The Adobe InDesign Toolbox" (10:10): with the White Arrow, click outside,diff --cc crates/tools/src/select.rsindex d7b8ed48e,3fdf457d3..5c8dab8bd--- a/crates/tools/src/select.rs+++ b/crates/tools/src/select.rs@@@ -700,22 -768,52 +768,65 @@@ impl SelectionTool&& let Some((id, si, ai, handle)) = anchor_at(cx, p){let at = anchor_spread_point(cx, id, si, ai);- self.drag = Drag::Anchor { id, si, ai, handle, start: p, at };- return vec![Action::Begin(if handle.is_some() { "Move Direction Handle".into() } else { "Move Anchor".into() })];+ let mut out = vec![];+ let mut others = vec![];+ if handle.is_none() {+ // InDesign's anchor point selection: a click selects the point, Shift+click+ // adds it or takes it away, and dragging a selected point moves all of them.+ let me = (ItemId(id), si, ai);+ let mut points = cx.selection.anchors.clone();+ let was = points.contains(&me);+ if ev.mods.shift && was {+ // Kept selected so a Shift-drag can constrain it; a click still takes it+ // away, on release, as for objects.+ self.anchor_release = Some(me);+ } else if ev.mods.shift {+ points.push(me);+ } else if !was {+ points = vec![me];+ }+ if points != cx.selection.anchors {+ out.push(Action::Exec("selection.set".into(), anchor_selection(cx, &points)));+ }+ others = points.iter().filter(|a| **a != me).map(|(i, s, a)| (i.0, *s, *a)).collect();+ }+ let label = if handle.is_some() {+ "Move Direction Handle"+ } else if others.is_empty() {+ "Move Anchor"+ } else {+ "Move Anchors"+ };+ self.drag = Drag::Anchor { id, si, ai, handle, start: p, at, others };+ out.push(Action::Begin(label.into()));+ return out;+ }+ // As in InDesign, the Direct Selection tool pressed on a corner or anchor of an object+ // that isn't selected selects it and moves just that point (Chris Nielsen's "The+ // InDesign Toolbox", 10:10: click outside, then pull a frame's corner).+ if self.direct+ && !ev.mods.shift+ && let Some((_, hit)) = cx.hit(p)+ && !cx.selection.contains(hit)+ && let Some((id, si, ai, None)) = anchor_at_in(cx, &[hit], p)+ {+ let at = anchor_spread_point(cx, id, si, ai);+ self.drag = Drag::Anchor { id, si, ai, handle: None, start: p, at, others: vec![] };+ return vec![Action::Exec("selection.set".into(), json!({"ids": [id], "content": true})), Action::Begin("Move Anchor".into())];}+ // As in InDesign, the Direct Selection tool pressed on a corner or anchor of an object+ // that isn't selected selects it and moves just that point (Chris Nielsen's "The+ // InDesign Toolbox", 10:10: click outside, then pull a frame's corner).+ if self.direct+ && !ev.mods.shift+ && let Some((_, hit)) = cx.hit(p)+ && !cx.selection.contains(hit)+ && let Some((id, si, ai, None)) = anchor_at_in(cx, &[hit], p)+ {+ let at = anchor_spread_point(cx, id, si, ai);+ self.drag = Drag::Anchor { id, si, ai, handle: None, start: p, at };+ return vec![Action::Exec("selection.set".into(), json!({"ids": [id], "content": false})), Action::Begin("Move Anchor".into())];+ }// A selected placed graphic's own handles resize it inside its frame (the// frame's anchors, under Direct Selection, come first).if let Some((id, h)) = content_handle_at(cx, p)@@@ -1086,20 -1190,23 +1207,25 @@@},);// dx and dy stay in canvas space. Snap.delta is spread space.- let corr = spread_delta_to_canvas(cx.layout.xf(spread), hit.delta);- if corr.x.is_finite() {- dx += corr.x;- }- if corr.y.is_finite() {- dy += corr.y;+ let mut corr = spread_delta_to_canvas(cx.layout.xf(spread), hit.delta);+ corr = Vec2::new(if corr.x.is_finite() { corr.x } else { 0.0 }, if corr.y.is_finite() { corr.y } else { 0.0 });+ // Shift: the snap moves the points along the constrained direction only.+ if ev.mods.shift && d.hypot() > 1e-9 {+ let dir = d / d.hypot();+ corr = dir * corr.dot(dir);}+ dx += corr.x;+ dy += corr.y;self.guides = hit.guides;}- let mut params = json!({"id": id, "anchors": [[si, ai]], "dx": dx, "dy": dy});+ // path.moveAnchors takes a spread-space delta.+ let delta = at.map_or(Vec2::new(dx, dy), |(spread, _)| cx.layout.delta_to_spread(spread, Vec2::new(dx, dy)));+ let mut params = json!({"id": id, "anchors": [[si, ai]], "dx": delta.x, "dy": delta.y});if let Some(h) = handle {params["handle"] = json!(h);+ } else if !others.is_empty() {+ let points: Vec<Value> = std::iter::once((id, si, ai)).chain(others).map(|(i, s, a)| json!([i, s, a])).collect();+ params = json!({"points": points, "dx": dx, "dy": dy});}vec![Action::Preview("path.moveAnchors".into(), params)]}diff --cc crates/tools/src/tests.rsindex 3b8ea0f75,c33cd4816..b505381c0--- a/crates/tools/src/tests.rs+++ b/crates/tools/src/tests.rs@@@ -2070,49 -1973,64 +2076,111 @@@ fn loaded_text_cursor_threads_into_a_frassert_eq!(t2.cursor(&cx2, q, Mods::default()), Cursor::NotAllowed);}+#[test]+fn direct_selection_click_on_one_of_several_selected_frames_selects_only_it() {+ let mut d = Document::new(&NewDocument::default());+ let a = add_rect(&mut d, Rect::new(100.0, 100.0, 200.0, 200.0));+ let b = add_rect(&mut d, Rect::new(300.0, 100.0, 400.0, 200.0));+ let (s, c, l) = (Selection::items(vec![a, b]), Cache::new(), CanvasLayout::new(&d, false));+ let cx = ctx(&d, &s, &c, &l);+ let p = spread_pt(&l, 150.0, 150.0);+ let mut t = create("directSelection");+ let acts = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, p.x, p.y));+ assert_eq!(acts, vec![Action::Exec("selection.set".into(), serde_json::json!({"ids": [a.0], "content": true}))]);+}++#[test]+fn pulling_a_corner_of_an_unselected_frame_selects_the_frame_not_its_content() {+ let mut d = Document::new(&NewDocument::default());+ let a = add_rect(&mut d, Rect::new(100.0, 100.0, 200.0, 200.0));+ let (s, c, l) = (Selection::default(), Cache::new(), CanvasLayout::new(&d, false));+ let cx = ctx(&d, &s, &c, &l);+ let p = spread_pt(&l, 200.0, 100.0);+ let mut t = create("directSelection");+ let acts = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, p.x, p.y));+ assert_eq!(+ acts,+ vec![Action::Exec("selection.set".into(), serde_json::json!({"ids": [a.0], "content": false})), Action::Begin("Move Anchor".into())]+ );+}++#[test]+fn anchor_drag_on_a_rotated_spread_sends_a_spread_space_delta() {+ let mut d = Document::new(&NewDocument::default());+ let a = add_rect(&mut d, Rect::new(100.0, 100.0, 200.0, 200.0));+ Arc::make_mut(&mut d.spreads[0]).pages[0].view_rotation = 1;+ let (s, c, l) = (Selection::items(vec![a]), Cache::new(), CanvasLayout::new(&d, false));+ let cx = ctx(&d, &s, &c, &l);+ let p = l.to_canvas(SpreadRef::Doc(0), Point::new(200.0, 100.0));+ let mut t = create("directSelection");+ t.pointer(&cx, &PointerEvent::new(PointerKind::Down, p.x, p.y));+ let acts = t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, p.x + 50.0, p.y));+ let [Action::Preview(cmd, params)] = acts.as_slice() else { panic!("{acts:?}") };+ assert_eq!(cmd, "path.moveAnchors");+ let want = l.delta_to_spread(SpreadRef::Doc(0), Vec2::new(50.0, 0.0));+ assert!(want.y.abs() > 1.0, "the view rotation turns a canvas x move into a spread y move: {want:?}");+ let (dx, dy) = (params["dx"].as_f64().unwrap(), params["dy"].as_f64().unwrap());+ assert!((dx - want.x).abs() < 1e-6 && (dy - want.y).abs() < 1e-6, "{params} want {want:?}");+}+++ /// Direct Selection selects anchor points with a marquee across several frames, and dragging one of+ /// them moves them all, as InDesign does when the top points of a row of frames are dragged to slant+ /// them (Zero2Graphic's page layout tutorial, 1:15).+ #[test]+ fn direct_selection_marquee_selects_points_of_several_frames_and_drags_them_together() {+ let mut d = Document::new(&NewDocument::default());+ let a = add_rect(&mut d, Rect::new(100.0, 100.0, 200.0, 200.0));+ let b = add_rect(&mut d, Rect::new(200.0, 100.0, 300.0, 200.0));+ let (c, l) = (Cache::new(), CanvasLayout::new(&d, false));+ let none = Selection::default();+ let mut t = create("directSelection");+ // A marquee around the top edges: the four top points, not the frames' bottom ones.+ let (p0, p1) = (spread_pt(&l, 80.0, 90.0), spread_pt(&l, 320.0, 110.0));+ t.pointer(&ctx(&d, &none, &c, &l), &PointerEvent::new(PointerKind::Down, p0.x, p0.y));+ t.pointer(&ctx(&d, &none, &c, &l), &PointerEvent::new(PointerKind::Drag, p1.x, p1.y));+ let up = t.pointer(&ctx(&d, &none, &c, &l), &PointerEvent::new(PointerKind::Up, p1.x, p1.y));+ let Some(Action::Exec(cmd, p)) = up.last() else { panic!("{up:?}") };+ assert_eq!(cmd, "selection.set");+ assert_eq!(p["ids"], serde_json::json!([a.0, b.0]));+ let mut got: Vec<(u64, u64, u64)> =+ p["anchors"].as_array().unwrap().iter().map(|v| (v[0].as_u64().unwrap(), v[1].as_u64().unwrap(), v[2].as_u64().unwrap())).collect();+ got.sort();+ assert_eq!(got, vec![(a.0, 0, 0), (a.0, 0, 1), (b.0, 0, 0), (b.0, 0, 1)]);+ // Those points selected: dragging one moves all four, in one preview.+ let sel = Selection { items: vec![a, b], anchors: vec![(a, 0, 0), (a, 0, 1), (b, 0, 0), (b, 0, 1)], ..Default::default() };+ let cx = ctx(&d, &sel, &c, &l);+ let at = spread_pt(&l, 200.0, 100.0);+ let down = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, at.x, at.y));+ assert_eq!(down, vec![Action::Begin("Move Anchors".into())]);+ let shift = Mods { shift: true, ..Default::default() };+ let drag = t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, at.x + 36.0, at.y + 3.0).with_mods(shift));+ let Some(Action::Preview(cmd, p)) = drag.last() else { panic!("{drag:?}") };+ assert_eq!(cmd, "path.moveAnchors");+ assert_eq!(p["points"].as_array().map(Vec::len), Some(4), "{p}");+ // Shift keeps the move horizontal.+ assert_eq!((p["dx"].as_f64(), p["dy"].as_f64()), (Some(36.0), Some(0.0)));+ assert_eq!(t.pointer(&cx, &PointerEvent::new(PointerKind::Up, at.x + 36.0, at.y)), vec![Action::Commit]);+ // A Shift-drag that starts on a selected point keeps it: all four move, constrained.+ t.pointer(&cx, &PointerEvent::new(PointerKind::Down, at.x, at.y).with_mods(shift));+ let drag = t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, at.x + 3.0, at.y + 30.0).with_mods(shift));+ let Some(Action::Preview(_, p)) = drag.last() else { panic!("{drag:?}") };+ assert_eq!(p["points"].as_array().map(Vec::len), Some(4), "{p}");+ assert!(p["dx"].as_f64().unwrap().abs() < 1e-9 && (p["dy"].as_f64().unwrap() - 30.0).abs() < 1e-9, "vertical: {p}");+ assert_eq!(t.pointer(&cx, &PointerEvent::new(PointerKind::Up, at.x, at.y + 30.0).with_mods(shift)), vec![Action::Commit]);+ // Shift+click on a selected point takes it out of the selection, on release; the arrow keys+ // move the points.+ let out = t.pointer(&cx, &PointerEvent::new(PointerKind::Down, at.x, at.y).with_mods(shift));+ assert!(!out.iter().any(|a| matches!(a, Action::Exec(..))), "kept while it may become a drag: {out:?}");+ // A jiggle inside the drag tolerance moves nothing: it is still a click.+ let jiggle = t.pointer(&cx, &PointerEvent::new(PointerKind::Drag, at.x + 1.0, at.y + 1.0).with_mods(shift));+ assert!(jiggle.is_empty(), "{jiggle:?}");+ let out = t.pointer(&cx, &PointerEvent::new(PointerKind::Up, at.x + 1.0, at.y + 1.0).with_mods(shift));+ let Some(Action::Exec(cmd, p)) = out.last() else { panic!("{out:?}") };+ assert_eq!(cmd, "selection.set");+ assert_eq!(p["anchors"].as_array().map(Vec::len), Some(3), "{p}");+ let keys = t.key(&cx, ToolKey::Right, Mods::default());+ assert!(+ matches!(keys.as_slice(), [Action::Exec(cmd, p)] if cmd == "path.moveAnchors" && p["points"].as_array().map(Vec::len) == Some(4)),+ "{keys:?}"+ );+ }