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 <noreply@anthropic.com>
This commit is contained in:
Zach Berry
2026-11-05 21:55:15 -06:00
co-authored by Claude Opus 5.5
parent f0c4bd6e6f
commit 996d67c1a6
3 changed files with 1 additions and 33 deletions
+1 -7
View File
@@ -338,10 +338,7 @@ pub(super) fn set(s: &mut Session, p: &Value) -> Result<Value> {
_ => 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<Value> {
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(())
-5
View File
@@ -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) => {
-21
View File
@@ -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();