diff --git a/crates/engine/src/cmd/retype.rs b/crates/engine/src/cmd/retype.rs index c9c4281935..563678293e 100644 --- a/crates/engine/src/cmd/retype.rs +++ b/crates/engine/src/cmd/retype.rs @@ -999,7 +999,7 @@ fn share_tracking(lines: &mut [Line], system_layout: bool) { /// `lines`, in paint order, as the objects Retype makes: runs of lines that stack as the lines of /// one paragraph do become one object ([`Block`]). `follows(a, b)`: shape `b` comes right after -/// shape `a`, with nothing between them in paint order. `budget`: see [`Block::made`]. +/// shape `a`, or is `a`, with nothing between them in paint order. `budget`: see [`Block::made`]. fn blocks(lines: Vec, follows: impl Fn(NodeId, NodeId) -> bool, system_layout: bool, budget: &mut usize) -> Vec { let mut out = vec![]; let mut block: Option = None; @@ -1489,8 +1489,9 @@ fn retype(s: &mut Session, p: &Value) -> Result { let mut seen = std::collections::HashSet::new(); unmatched.retain(|id| !kept.contains(id) && seen.insert(*id)); let at: std::collections::HashMap = pieces.iter().enumerate().map(|(i, pc)| (pc.id, i)).collect(); + // Lines split from one compound path share its shape, with nothing between them. let follows = |a: NodeId, b: NodeId| match (at.get(&a), at.get(&b)) { - (Some(i), Some(j)) => *j == i + 1 && pieces.get(*j).is_some_and(|pc| !pc.after_barrier), + (Some(i), Some(j)) => *j == *i || (*j == i + 1 && pieces.get(*j).is_some_and(|pc| !pc.after_barrier)), _ => false, }; // Joining lines takes at most four tries' work per glyph (see [`Block::made`]), with room diff --git a/crates/engine/src/cmd/retype_tests.rs b/crates/engine/src/cmd/retype_tests.rs index 3882c50f5e..e5231b47b0 100644 --- a/crates/engine/src/cmd/retype_tests.rs +++ b/crates/engine/src/cmd/retype_tests.rs @@ -1146,9 +1146,10 @@ fn a_lone_period_in_a_compound_selected_alone_stays_an_outline() { #[test] fn lines_from_one_compound_path_keep_their_order() { let mut s = session(); - // Two lines of outlines made into one compound path. + // Two lines of outlines made into one compound path, farther apart than the lines of one + // paragraph, so each stays an object of its own. let top = outlined(&mut s, json!({"x": 40, "y": 100, "text": "Tim", "size": 40})); - let low = outlined(&mut s, json!({"x": 40, "y": 220, "text": "Ham", "size": 40})); + let low = outlined(&mut s, json!({"x": 40, "y": 300, "text": "Ham", "size": 40})); let mut glyphs = children_of(&s, top); glyphs.extend(children_of(&s, low)); s.execute("select.set", &json!({"ids": glyphs})).unwrap(); @@ -1166,6 +1167,23 @@ fn lines_from_one_compound_path_keep_their_order() { assert!(at[first] < at[second], "{texts:?} at {at:?}"); } +#[test] +fn stacked_lines_from_one_compound_path_become_one_object() { + let mut s = session(); + // Two lines of one paragraph, outlined and made into one compound path: they join as the + // lines of separate outlines do. + let text = "Tim\nHam"; + let g = outlined(&mut s, json!({"x": 40, "y": 100, "text": text, "size": 40})); + let glyphs = children_of(&s, g); + s.execute("select.set", &json!({"ids": glyphs})).unwrap(); + let c = s.execute("object.compoundPath.make", &json!({})).unwrap()["id"].as_u64().unwrap(); + s.execute("select.set", &json!({"ids": [c]})).unwrap(); + let r = s.execute("type.retype", &json!({})).unwrap(); + assert_eq!(r["texts"], json!([text]), "{r}"); + assert_eq!(r["unmatched"], json!([]), "{r}"); + assert!(s.doc().unwrap().doc.node(NodeId(c)).is_none(), "the compound becomes the type"); +} + #[test] fn a_compound_whose_parts_are_not_all_glyphs_stays_whole() { let mut s = session(); diff --git a/docs/mcp.md b/docs/mcp.md index 910853c024..412809d4f8 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -12526,7 +12526,7 @@ tracking their own gaps give. These rules are VectorCraft's own. Each entry of t ## Retype several lines -`type.retype` joins lines that follow each other in paint order, with the same group, paint, font, size, turn and +`type.retype` joins lines that follow each other in paint order (lines split from one compound path do), with the same group, paint, font, size, turn and tracking (an untracked line of one or two glyphs takes the tracking of the others), into one type object when each line's baseline is the same distance below the one before (between 0.25 and 3 times the size) and the lines line up at their starts, ends or centers. The object is area type with Convert To Area Type's frame, its lines separated by line breaks, with left, right or center alignment, checked in that order. Its