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();