From ffcb3fe68a0ec4e41b1590100de60023c2a46157 Mon Sep 17 00:00:00 2001 From: Zach Berry <1112351+zberry@users.noreply.github.com> Date: Sun, 18 Oct 2026 13:45:08 -0500 Subject: [PATCH 1/6] Connector default sites face the other shape; formatting set before the text survives text.set shape.connect with no sites given picked the closest pair of sites, which for a diagonal neighbour chose a side site and drew the arrow across the boxes. Each shape now uses the site that faces the other along the direction between their centres (a box mostly below is left from the bottom), which is where a person glues an arrow; the params doc says so. format.size, format.bold, format.color on a shape that has no text yet kept nothing, so the size vanished when set_text then landed the text. An empty body now keeps that formatting on the paragraph's end mark and text.set keeps the first run's properties, or those, so the two work in either order. A test for each. Co-Authored-By: Claude Fable 5.1 --- crates/engine/src/cmd/shape.rs | 2 +- crates/engine/src/cmd/shape/freeform.rs | 36 +++++++++++++++--------- crates/engine/src/cmd/text/caret.rs | 8 +++++- crates/engine/src/cmd/text/formatting.rs | 5 ++++ crates/engine/src/tests.rs | 35 +++++++++++++++++++++++ 5 files changed, 70 insertions(+), 16 deletions(-) diff --git a/crates/engine/src/cmd/shape.rs b/crates/engine/src/cmd/shape.rs index a447a20b9..db91a48ed 100644 --- a/crates/engine/src/cmd/shape.rs +++ b/crates/engine/src/cmd/shape.rs @@ -34,7 +34,7 @@ pub fn specs() -> Vec { "Connect Shapes", [], None, - "{from: shape id, to: shape id, fromSite?, toSite?: site index (default: the closest pair), id?: existing line to glue (else a new connector), preset?: straightConnector1|bentConnector3|curvedConnector3} → {id}", + "{from: shape id, to: shape id, fromSite?, toSite?: site index (default: the sites facing each other along the dominant direction between the shapes; a box has 0 top, 1 left, 2 bottom, 3 right; shape.sites lists them), id?: existing line to glue (else a new connector), preset?: straightConnector1|bentConnector3|curvedConnector3} → {id}", has_slide, connect ), diff --git a/crates/engine/src/cmd/shape/freeform.rs b/crates/engine/src/cmd/shape/freeform.rs index 5fd299c9e..b068f86ac 100644 --- a/crates/engine/src/cmd/shape/freeform.rs +++ b/crates/engine/src/cmd/shape/freeform.rs @@ -24,21 +24,29 @@ pub(super) fn connect(s: &mut Session, p: &Value) -> Result { return Err(bad("shape.connect", "both shapes need connection sites (lines and groups have none)")); } let pick = |v: &[deckcraft_geom::Point], key: &str| usize_param(p, key).filter(|i| *i < v.len()); - let (ia, ib) = match (pick(&a, "fromSite"), pick(&b, "toSite")) { - (Some(i), Some(j)) => (i, j), - (fi, fj) => { - let mut best = (f64::MAX, 0, 0); - for (i, pa) in a.iter().enumerate().filter(|(i, _)| fi.is_none_or(|f| f == *i)) { - for (j, pb) in b.iter().enumerate().filter(|(j, _)| fj.is_none_or(|f| f == *j)) { - let d = (*pa - *pb).hypot(); - if d < best.0 { - best = (d, i, j); - } - } - } - (best.1, best.2) - } + // A site left unsaid is the one facing the other shape along the dominant direction between + // the two (a box mostly below is left from the bottom), which is where a person glues an + // arrow; "the closest pair" chose a side site for a diagonal neighbour and crossed boxes. + let centre = |v: &[deckcraft_geom::Point]| { + let n = v.len().max(1) as f64; + deckcraft_geom::Point::new(v.iter().map(|q| q.x).sum::() / n, v.iter().map(|q| q.y).sum::() / n) }; + let (ca, cb) = (centre(&a), centre(&b)); + let facing = |v: &[deckcraft_geom::Point], c: deckcraft_geom::Point, dx: f64, dy: f64| { + let len = dx.hypot(dy).max(1e-9); + v.iter() + .enumerate() + .map(|(i, q)| { + let (sx, sy) = (q.x - c.x, q.y - c.y); + let sl = sx.hypot(sy).max(1e-9); + (i, (sx * dx + sy * dy) / (sl * len)) + }) + .max_by(|p, q| p.1.total_cmp(&q.1)) + .map(|(i, _)| i) + .unwrap_or(0) + }; + let ia = pick(&a, "fromSite").unwrap_or_else(|| facing(&a, ca, cb.x - ca.x, cb.y - ca.y)); + let ib = pick(&b, "toSite").unwrap_or_else(|| facing(&b, cb, ca.x - cb.x, ca.y - cb.y)); let (p0, p1) = (a[ia], b[ib]); let id = match id_param(p, "id", "shape.connect")? { // The ends are in slide space and rerouting follows the slide's own connectors, so a line diff --git a/crates/engine/src/cmd/text/caret.rs b/crates/engine/src/cmd/text/caret.rs index c7305d62e..845e72d60 100644 --- a/crates/engine/src/cmd/text/caret.rs +++ b/crates/engine/src/cmd/text/caret.rs @@ -338,7 +338,10 @@ pub(super) fn set(s: &mut Session, p: &Value) -> Result { _ => Some(sh.text.get_or_insert_with(TextBody::default)), }; let Some(body) = target else { return Err(bad("text.set", "no text here (tables need `cell`)")) }; - let keep = body.paragraphs.first().and_then(|p| p.runs.first()).map(|r| r.props.clone()).unwrap_or_default(); + // The first run's formatting, or for text that is still empty the formatting its end + // mark holds (format.* before any text lands there), so a size set before text.set survives. + let keep = + body.paragraphs.first().map(|p| p.runs.first().map(|r| r.props.clone()).unwrap_or_else(|| p.end_props.clone())).unwrap_or_default(); let levels: Vec<(u8, deckcraft_model::text::ParaProps)> = body.paragraphs.iter().map(|p| (p.level, p.props.clone())).collect(); let mut nb = TextBody::from_text(&text); for (i, para) in nb.paragraphs.iter_mut().enumerate() { @@ -353,6 +356,9 @@ pub(super) fn set(s: &mut Session, p: &Value) -> Result { for r in &mut para.runs { r.props = keep.clone(); } + // The end mark keeps it too, so an empty `text` (no runs) carries the formatting to + // the text set next. + para.end_props = keep.clone(); } body.paragraphs = nb.paragraphs; Ok(()) diff --git a/crates/engine/src/cmd/text/formatting.rs b/crates/engine/src/cmd/text/formatting.rs index d942ee282..60923c9c2 100644 --- a/crates/engine/src/cmd/text/formatting.rs +++ b/crates/engine/src/cmd/text/formatting.rs @@ -72,6 +72,11 @@ pub(crate) fn format_run_levels( } _ => { let body = sh.text.get_or_insert_with(TextBody::default); + // Text that is still empty keeps the formatting on an end mark, so a size set + // before the text lands survives it; a body with no paragraph has none. + if body.paragraphs.is_empty() { + body.paragraphs.push(Default::default()); + } let eff = effective.iter().find(|(i, _)| *i == id).map(|(_, e)| e); match eff { Some(eff) => { diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index ca1f93d26..af36218e0 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -6750,6 +6750,41 @@ fn invalid_slide_index_never_falls_back_to_the_selection_in_export_commands() { let _ = std::fs::remove_dir_all(&dir); } +/// G6: with no sites given, shape.connect joins the sites that face each other along the +/// dominant direction between the two shapes (a box mostly below leaves from the bottom), not +/// "the closest pair", which for a diagonal neighbour picked a side site and crossed boxes. +#[test] +fn connector_default_sites_follow_the_dominant_direction() { + let mut s = session(); + let a = s.execute("shape.insert", &json!({"preset": "rect", "rect": [0, 0, 100, 50]})).unwrap()["id"].as_u64().unwrap(); + let diag = s.execute("shape.insert", &json!({"preset": "rect", "rect": [150, 200, 100, 50]})).unwrap()["id"].as_u64().unwrap(); + let r = s.execute("shape.connect", &json!({"from": a, "to": diag})).unwrap(); + assert_eq!((r["fromSite"].as_u64(), r["toSite"].as_u64()), (Some(2), Some(0)), "mostly below: bottom → top, not right → left: {r}"); + let r = s.execute("shape.connect", &json!({"from": diag, "to": a})).unwrap(); + assert_eq!((r["fromSite"].as_u64(), r["toSite"].as_u64()), (Some(0), Some(2)), "and back: top → bottom: {r}"); +} + +/// A size (or colour, bold…) set on a shape before it has any text survives the text that is +/// then set: text.set keeps the first run's properties, and an empty paragraph keeps them on its +/// end mark, which is what the agent's format.size then set_text sequence relies on. +#[test] +fn text_set_keeps_the_formatting_of_an_empty_shape() { + let mut s = session(); + let id = s.execute("shape.insert", &json!({"preset": "rect", "rect": [10, 10, 300, 60]})).unwrap()["id"].as_u64().unwrap(); + s.execute("format.size", &json!({"size": 30})).unwrap(); + s.execute("format.bold", &json!({"on": true})).unwrap(); + s.execute("text.set", &json!({"id": id, "text": "Hello"})).unwrap(); + let props = + |s: &Session| s.doc().unwrap().shape(deckcraft_model::ShapeId(id as u32)).unwrap().text.as_ref().unwrap().paragraphs[0].runs[0].props.clone(); + let run = props(&s); + assert_eq!((run.size, run.bold), (Some(30.0), Some(true)), "{run:?}"); + // Emptied and filled again: the empty paragraph's end mark carried the formatting. + s.execute("text.set", &json!({"id": id, "text": ""})).unwrap(); + s.execute("text.set", &json!({"id": id, "text": "Again"})).unwrap(); + let run = props(&s); + assert_eq!((run.size, run.bold), (Some(30.0), Some(true)), "after an empty text.set: {run:?}"); +} + #[test] fn highlight_with_an_invalid_colour_is_rejected_and_keeps_the_highlight() { let mut s = session(); From 6cf52800385164141ed09b7edd27d644589304fb Mon Sep 17 00:00:00 2001 From: Zach Berry <1112351+zberry@users.noreply.github.com> Date: Sun, 18 Oct 2026 18:26:52 -0500 Subject: [PATCH 2/6] shape.connect takes the direction between the shapes' box centres, not the means of their sites The mean of a shape's connection sites is off its centre when the sites are not symmetric (a triangle's lie mostly along its base), which pulled the dominant direction sideways and glued an arrow to a box's side when the box was mostly below. The centres come from xfrm_of, so placeholders and tables are measured as drawn. Co-Authored-By: Claude Fable 5.1 --- crates/engine/src/cmd/shape/freeform.rs | 9 ++++----- crates/engine/src/tests.rs | 7 +++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/cmd/shape/freeform.rs b/crates/engine/src/cmd/shape/freeform.rs index b068f86ac..b85e9b52f 100644 --- a/crates/engine/src/cmd/shape/freeform.rs +++ b/crates/engine/src/cmd/shape/freeform.rs @@ -27,11 +27,10 @@ pub(super) fn connect(s: &mut Session, p: &Value) -> Result { // A site left unsaid is the one facing the other shape along the dominant direction between // the two (a box mostly below is left from the bottom), which is where a person glues an // arrow; "the closest pair" chose a side site for a diagonal neighbour and crossed boxes. - let centre = |v: &[deckcraft_geom::Point]| { - let n = v.len().max(1) as f64; - deckcraft_geom::Point::new(v.iter().map(|q| q.x).sum::() / n, v.iter().map(|q| q.y).sum::() / n) - }; - let (ca, cb) = (centre(&a), centre(&b)); + // The direction runs between the shapes' box centres: the mean of the sites is off-centre + // for a shape whose sites are not symmetric (a triangle's lie mostly along its base). + let centre = |id| st.shape(id).map(|sh| xfrm_of(&st.doc, &st.selection, sh).center()).unwrap_or_default(); + let (ca, cb) = (centre(from), centre(to)); let facing = |v: &[deckcraft_geom::Point], c: deckcraft_geom::Point, dx: f64, dy: f64| { let len = dx.hypot(dy).max(1e-9); v.iter() diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index af36218e0..135d83df5 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -6762,6 +6762,13 @@ fn connector_default_sites_follow_the_dominant_direction() { assert_eq!((r["fromSite"].as_u64(), r["toSite"].as_u64()), (Some(2), Some(0)), "mostly below: bottom → top, not right → left: {r}"); let r = s.execute("shape.connect", &json!({"from": diag, "to": a})).unwrap(); assert_eq!((r["fromSite"].as_u64(), r["toSite"].as_u64()), (Some(0), Some(2)), "and back: top → bottom: {r}"); + // The direction runs between the shapes' centres, not between the means of their sites: a + // triangle's sites lie mostly along its base, which pulled the direction sideways and chose + // the box's left site for a box that is mostly below. + let tri = s.execute("shape.insert", &json!({"preset": "triangle", "rect": [400, 0, 100, 100]})).unwrap()["id"].as_u64().unwrap(); + let below = s.execute("shape.insert", &json!({"preset": "rect", "rect": [520, 155, 100, 50]})).unwrap()["id"].as_u64().unwrap(); + let r = s.execute("shape.connect", &json!({"from": tri, "to": below})).unwrap(); + assert_eq!(r["toSite"].as_u64(), Some(0), "centre to centre is mostly down: the box's top, not its left: {r}"); } /// A size (or colour, bold…) set on a shape before it has any text survives the text that is From 0666ef9980924d61577fa40cbeeba8256e316320 Mon Sep 17 00:00:00 2001 From: Zach Berry <1112351+zberry@users.noreply.github.com> Date: Thu, 29 Oct 2026 18:01:35 -0500 Subject: [PATCH 3/6] Imports after upstream replaced wildcard imports (#1444) Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/shape/freeform.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/shape/freeform.rs b/crates/engine/src/cmd/shape/freeform.rs index b85e9b52f..1b853b14d 100644 --- a/crates/engine/src/cmd/shape/freeform.rs +++ b/crates/engine/src/cmd/shape/freeform.rs @@ -1,4 +1,4 @@ -use super::{ColorRef, Fill, Geom, Line, NO_ID_SPACE, Result, Session, Value, bad, bool_or, id_param, json, str_param, usize_param}; +use super::{ColorRef, Fill, Geom, Line, NO_ID_SPACE, Result, Session, Value, bad, bool_or, id_param, json, str_param, usize_param, xfrm_of}; pub(super) fn sites(s: &mut Session, p: &Value) -> Result { let id = id_param(p, "id", "shape.sites")?.ok_or_else(|| bad("shape.sites", "missing `id`"))?; From 39d8c5d7dd89a403b2816c2fe3c62acf2057269f Mon Sep 17 00:00:00 2001 From: Zach Berry <1112351+zberry@users.noreply.github.com> Date: Mon, 2 Nov 2026 17:02:15 -0600 Subject: [PATCH 4/6] shape.connect: a tie between sites goes to the lower site index The default sites follow the direction between the shapes' centres, but an exact diagonal ties a box's bottom with its right side (and its top with its left), and shapes with one centre tie every site; the pick then fell to whichever site came last. A tie now goes to the lower index: an exact diagonal connects bottom to top, and shapes with one centre both take site 0. The spec says so. Tests for both. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/shape.rs | 2 +- crates/engine/src/cmd/shape/freeform.rs | 25 ++++++++++++++++--------- crates/engine/src/tests.rs | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/crates/engine/src/cmd/shape.rs b/crates/engine/src/cmd/shape.rs index db91a48ed..ee911363c 100644 --- a/crates/engine/src/cmd/shape.rs +++ b/crates/engine/src/cmd/shape.rs @@ -34,7 +34,7 @@ pub fn specs() -> Vec { "Connect Shapes", [], None, - "{from: shape id, to: shape id, fromSite?, toSite?: site index (default: the sites facing each other along the dominant direction between the shapes; a box has 0 top, 1 left, 2 bottom, 3 right; shape.sites lists them), id?: existing line to glue (else a new connector), preset?: straightConnector1|bentConnector3|curvedConnector3} → {id}", + "{from: shape id, to: shape id, fromSite?, toSite?: site index (default: the sites facing each other along the dominant direction between the shapes, a tie to the lower index; a box has 0 top, 1 left, 2 bottom, 3 right; shape.sites lists them), id?: existing line to glue (else a new connector), preset?: straightConnector1|bentConnector3|curvedConnector3} → {id}", has_slide, connect ), diff --git a/crates/engine/src/cmd/shape/freeform.rs b/crates/engine/src/cmd/shape/freeform.rs index 1b853b14d..54321c84c 100644 --- a/crates/engine/src/cmd/shape/freeform.rs +++ b/crates/engine/src/cmd/shape/freeform.rs @@ -29,20 +29,27 @@ pub(super) fn connect(s: &mut Session, p: &Value) -> Result { // arrow; "the closest pair" chose a side site for a diagonal neighbour and crossed boxes. // The direction runs between the shapes' box centres: the mean of the sites is off-centre // for a shape whose sites are not symmetric (a triangle's lie mostly along its base). - let centre = |id| st.shape(id).map(|sh| xfrm_of(&st.doc, &st.selection, sh).center()).unwrap_or_default(); + // In slide space, as the sites are: a shape inside a group is placed where the group draws it. + let centre = |id| { + crate::connect::locate(&st.doc, &st.selection, st.shapes(), id) + .map(|(sh, to_abs)| to_abs * xfrm_of(&st.doc, &st.selection, sh).center()) + .unwrap_or_default() + }; let (ca, cb) = (centre(from), centre(to)); + // A tie goes to the lowest site index: an exact diagonal leaves a box from its bottom (site 2, + // before the right side, 3) and enters the other at its top (0, before the left side, 1), and + // shapes with one centre, where every direction is as good, both take site 0. let facing = |v: &[deckcraft_geom::Point], c: deckcraft_geom::Point, dx: f64, dy: f64| { let len = dx.hypot(dy).max(1e-9); - v.iter() - .enumerate() - .map(|(i, q)| { + let cos: Vec = v + .iter() + .map(|q| { let (sx, sy) = (q.x - c.x, q.y - c.y); - let sl = sx.hypot(sy).max(1e-9); - (i, (sx * dx + sy * dy) / (sl * len)) + (sx * dx + sy * dy) / (sx.hypot(sy).max(1e-9) * len) }) - .max_by(|p, q| p.1.total_cmp(&q.1)) - .map(|(i, _)| i) - .unwrap_or(0) + .collect(); + let best = cos.iter().copied().fold(f64::NEG_INFINITY, f64::max); + cos.iter().position(|x| *x >= best - 1e-9).unwrap_or(0) }; let ia = pick(&a, "fromSite").unwrap_or_else(|| facing(&a, ca, cb.x - ca.x, cb.y - ca.y)); let ib = pick(&b, "toSite").unwrap_or_else(|| facing(&b, cb, ca.x - cb.x, ca.y - cb.y)); diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 135d83df5..64e48696c 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -6769,6 +6769,20 @@ fn connector_default_sites_follow_the_dominant_direction() { let below = s.execute("shape.insert", &json!({"preset": "rect", "rect": [520, 155, 100, 50]})).unwrap()["id"].as_u64().unwrap(); let r = s.execute("shape.connect", &json!({"from": tri, "to": below})).unwrap(); assert_eq!(r["toSite"].as_u64(), Some(0), "centre to centre is mostly down: the box's top, not its left: {r}"); + // An exact diagonal ties the bottom with the right side (and the top with the left): the lower + // site index wins, so bottom → top, and top → bottom back. + let p = s.execute("shape.insert", &json!({"preset": "rect", "rect": [0, 300, 100, 50]})).unwrap()["id"].as_u64().unwrap(); + let q = s.execute("shape.insert", &json!({"preset": "rect", "rect": [200, 500, 100, 50]})).unwrap()["id"].as_u64().unwrap(); + let sites = |s: &mut Session, from: u64, to: u64| { + let r = s.execute("shape.connect", &json!({"from": from, "to": to})).unwrap(); + (r["fromSite"].as_u64(), r["toSite"].as_u64()) + }; + assert_eq!(sites(&mut s, p, q), (Some(2), Some(0))); + assert_eq!(sites(&mut s, q, p), (Some(0), Some(2))); + // Shapes with one centre tie every site: site 0 on both. + let big = s.execute("shape.insert", &json!({"preset": "rect", "rect": [600, 300, 200, 100]})).unwrap()["id"].as_u64().unwrap(); + let small = s.execute("shape.insert", &json!({"preset": "rect", "rect": [650, 325, 100, 50]})).unwrap()["id"].as_u64().unwrap(); + assert_eq!(sites(&mut s, big, small), (Some(0), Some(0))); } /// A size (or colour, bold…) set on a shape before it has any text survives the text that is From f0c4bd6e6fcd5a478ede61ecc06ba73ed645c930 Mon Sep 17 00:00:00 2001 From: Zach Berry <1112351+zberry@users.noreply.github.com> Date: Thu, 5 Nov 2026 21:53:02 -0600 Subject: [PATCH 5/6] shape.connect: with one site given, the other end is the site closest to it The facing rule is for when neither site is given; with exactly one given the other end is the other shape's site closest to it, as it was before the default changed. Test extended. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/shape.rs | 2 +- crates/engine/src/cmd/shape/freeform.rs | 20 ++++++++++++++++++-- crates/engine/src/tests.rs | 9 +++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/crates/engine/src/cmd/shape.rs b/crates/engine/src/cmd/shape.rs index ee911363c..3c00ac4dd 100644 --- a/crates/engine/src/cmd/shape.rs +++ b/crates/engine/src/cmd/shape.rs @@ -34,7 +34,7 @@ pub fn specs() -> Vec { "Connect Shapes", [], None, - "{from: shape id, to: shape id, fromSite?, toSite?: site index (default: the sites facing each other along the dominant direction between the shapes, a tie to the lower index; a box has 0 top, 1 left, 2 bottom, 3 right; shape.sites lists them), id?: existing line to glue (else a new connector), preset?: straightConnector1|bentConnector3|curvedConnector3} → {id}", + "{from: shape id, to: shape id, fromSite?, toSite?: site index (default: with neither given, the sites facing each other along the dominant direction between the shapes, a tie to the lower index; with one given, the closest site of the other shape; a box has 0 top, 1 left, 2 bottom, 3 right; shape.sites lists them), id?: existing line to glue (else a new connector), preset?: straightConnector1|bentConnector3|curvedConnector3} → {id}", has_slide, connect ), diff --git a/crates/engine/src/cmd/shape/freeform.rs b/crates/engine/src/cmd/shape/freeform.rs index 54321c84c..da6fe408e 100644 --- a/crates/engine/src/cmd/shape/freeform.rs +++ b/crates/engine/src/cmd/shape/freeform.rs @@ -51,8 +51,24 @@ pub(super) fn connect(s: &mut Session, p: &Value) -> Result { let best = cos.iter().copied().fold(f64::NEG_INFINITY, f64::max); cos.iter().position(|x| *x >= best - 1e-9).unwrap_or(0) }; - let ia = pick(&a, "fromSite").unwrap_or_else(|| facing(&a, ca, cb.x - ca.x, cb.y - ca.y)); - let ib = pick(&b, "toSite").unwrap_or_else(|| facing(&b, cb, ca.x - cb.x, ca.y - cb.y)); + // With one site given, the other end is the site of the other shape closest to it, as before; + // the facing rule is for the case where neither is given. + let closest = |v: &[deckcraft_geom::Point], to: deckcraft_geom::Point| { + let mut best = (f64::MAX, 0); + for (i, q) in v.iter().enumerate() { + let d = (*q - to).hypot(); + if d < best.0 { + best = (d, i); + } + } + best.1 + }; + let (ia, ib) = match (pick(&a, "fromSite"), pick(&b, "toSite")) { + (Some(i), Some(j)) => (i, j), + (Some(i), None) => (i, closest(&b, a[i])), + (None, Some(j)) => (closest(&a, b[j]), j), + (None, None) => (facing(&a, ca, cb.x - ca.x, cb.y - ca.y), facing(&b, cb, ca.x - cb.x, ca.y - cb.y)), + }; let (p0, p1) = (a[ia], b[ib]); let id = match id_param(p, "id", "shape.connect")? { // The ends are in slide space and rerouting follows the slide's own connectors, so a line diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 64e48696c..5b89efe49 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -6783,6 +6783,15 @@ fn connector_default_sites_follow_the_dominant_direction() { let big = s.execute("shape.insert", &json!({"preset": "rect", "rect": [600, 300, 200, 100]})).unwrap()["id"].as_u64().unwrap(); let small = s.execute("shape.insert", &json!({"preset": "rect", "rect": [650, 325, 100, 50]})).unwrap()["id"].as_u64().unwrap(); assert_eq!(sites(&mut s, big, small), (Some(0), Some(0))); + // One site given: the other end is the other shape's site closest to it, as before the facing + // rule (which is for when neither is given). From a's right side (100, 25) the diagonal box's + // top (200, 200) is nearest; to its left side (150, 225), a's bottom (50, 50). + let r = s.execute("shape.connect", &json!({"from": a, "to": diag, "fromSite": 3})).unwrap(); + assert_eq!((r["fromSite"].as_u64(), r["toSite"].as_u64()), (Some(3), Some(0)), "fromSite only: {r}"); + let r = s.execute("shape.connect", &json!({"from": a, "to": diag, "toSite": 1})).unwrap(); + assert_eq!((r["fromSite"].as_u64(), r["toSite"].as_u64()), (Some(2), Some(1)), "toSite only: {r}"); + let r = s.execute("shape.connect", &json!({"from": a, "to": diag, "fromSite": 2, "toSite": 3})).unwrap(); + assert_eq!((r["fromSite"].as_u64(), r["toSite"].as_u64()), (Some(2), Some(3)), "both given: {r}"); } /// A size (or colour, bold…) set on a shape before it has any text survives the text that is From 996d67c1a62741d8b76a3eb2ea914b63b07dab38 Mon Sep 17 00:00:00 2001 From: Zach Berry <1112351+zberry@users.noreply.github.com> Date: Thu, 5 Nov 2026 21:55:15 -0600 Subject: [PATCH 6/6] Move the empty-shape formatting fix to its own change It is unrelated to the connector default sites; it is now its own change on its own branch. Co-Authored-By: Claude Opus 5.5 --- crates/engine/src/cmd/text/caret.rs | 8 +------- crates/engine/src/cmd/text/formatting.rs | 5 ----- crates/engine/src/tests.rs | 21 --------------------- 3 files changed, 1 insertion(+), 33 deletions(-) diff --git a/crates/engine/src/cmd/text/caret.rs b/crates/engine/src/cmd/text/caret.rs index 845e72d60..c7305d62e 100644 --- a/crates/engine/src/cmd/text/caret.rs +++ b/crates/engine/src/cmd/text/caret.rs @@ -338,10 +338,7 @@ pub(super) fn set(s: &mut Session, p: &Value) -> Result { _ => Some(sh.text.get_or_insert_with(TextBody::default)), }; let Some(body) = target else { return Err(bad("text.set", "no text here (tables need `cell`)")) }; - // The first run's formatting, or for text that is still empty the formatting its end - // mark holds (format.* before any text lands there), so a size set before text.set survives. - let keep = - body.paragraphs.first().map(|p| p.runs.first().map(|r| r.props.clone()).unwrap_or_else(|| p.end_props.clone())).unwrap_or_default(); + let keep = body.paragraphs.first().and_then(|p| p.runs.first()).map(|r| r.props.clone()).unwrap_or_default(); let levels: Vec<(u8, deckcraft_model::text::ParaProps)> = body.paragraphs.iter().map(|p| (p.level, p.props.clone())).collect(); let mut nb = TextBody::from_text(&text); for (i, para) in nb.paragraphs.iter_mut().enumerate() { @@ -356,9 +353,6 @@ pub(super) fn set(s: &mut Session, p: &Value) -> Result { for r in &mut para.runs { r.props = keep.clone(); } - // The end mark keeps it too, so an empty `text` (no runs) carries the formatting to - // the text set next. - para.end_props = keep.clone(); } body.paragraphs = nb.paragraphs; Ok(()) diff --git a/crates/engine/src/cmd/text/formatting.rs b/crates/engine/src/cmd/text/formatting.rs index 60923c9c2..d942ee282 100644 --- a/crates/engine/src/cmd/text/formatting.rs +++ b/crates/engine/src/cmd/text/formatting.rs @@ -72,11 +72,6 @@ pub(crate) fn format_run_levels( } _ => { let body = sh.text.get_or_insert_with(TextBody::default); - // Text that is still empty keeps the formatting on an end mark, so a size set - // before the text lands survives it; a body with no paragraph has none. - if body.paragraphs.is_empty() { - body.paragraphs.push(Default::default()); - } let eff = effective.iter().find(|(i, _)| *i == id).map(|(_, e)| e); match eff { Some(eff) => { diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 5b89efe49..dd0963cfb 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -6794,27 +6794,6 @@ fn connector_default_sites_follow_the_dominant_direction() { assert_eq!((r["fromSite"].as_u64(), r["toSite"].as_u64()), (Some(2), Some(3)), "both given: {r}"); } -/// A size (or colour, bold…) set on a shape before it has any text survives the text that is -/// then set: text.set keeps the first run's properties, and an empty paragraph keeps them on its -/// end mark, which is what the agent's format.size then set_text sequence relies on. -#[test] -fn text_set_keeps_the_formatting_of_an_empty_shape() { - let mut s = session(); - let id = s.execute("shape.insert", &json!({"preset": "rect", "rect": [10, 10, 300, 60]})).unwrap()["id"].as_u64().unwrap(); - s.execute("format.size", &json!({"size": 30})).unwrap(); - s.execute("format.bold", &json!({"on": true})).unwrap(); - s.execute("text.set", &json!({"id": id, "text": "Hello"})).unwrap(); - let props = - |s: &Session| s.doc().unwrap().shape(deckcraft_model::ShapeId(id as u32)).unwrap().text.as_ref().unwrap().paragraphs[0].runs[0].props.clone(); - let run = props(&s); - assert_eq!((run.size, run.bold), (Some(30.0), Some(true)), "{run:?}"); - // Emptied and filled again: the empty paragraph's end mark carried the formatting. - s.execute("text.set", &json!({"id": id, "text": ""})).unwrap(); - s.execute("text.set", &json!({"id": id, "text": "Again"})).unwrap(); - let run = props(&s); - assert_eq!((run.size, run.bold), (Some(30.0), Some(true)), "after an empty text.set: {run:?}"); -} - #[test] fn highlight_with_an_invalid_colour_is_rejected_and_keeps_the_highlight() { let mut s = session();