DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
fix(type): text typed on a blank line takes the line's paragraph mark format
aiongg6b43209e3076
diff --git a/ROADMAP.md b/ROADMAP.mdindex 9dc6ececb..9ca5c3010 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -347,7 +347,7 @@ list) · [roadmap.md](docs/roadmap.md) (milestones, plan) · [parity-checklist.mNewest first.-- **2026-10-15** · Character formatting set at a caret on a blank line (an empty paragraph) applies to the text then typed there as well as to the line's paragraph mark; typed text used to take the previous paragraph's format. No readiness percentage change.+- **2026-10-15** · Character formatting set at a caret on a blank line (an empty paragraph) applies to the line's paragraph mark and to the text typed there, also after the caret has left the line and come back; typed text used to take the previous paragraph's format. No readiness percentage change.- **2026-10-14** · The Type tool draws a new text frame over a locked empty frame, as InDesign does, instead of turning the locked frame into a text frame. No readiness percentage change.- **2026-10-14** · 100% black shows as pure black on screen by default, as InDesign's Appearance of Black does out of the box (Display All Blacks as Rich Black); Preferences › Appearance of Black › Display All Blacks Accurately still shows it as the dark grey it prints, and a saved choice is kept. No readiness percentage change.- **2026-10-14** · Pathfinder keeps the frontmost object, as InDesign does: a photo placed over shapes and intersected with them shows through the shapes (it was dropped, and the shapes kept their black fill); Add, Exclude Overlap and Minus Back take the front object's fill too, Subtract still keeps the back one. No readiness percentage change.diff --git a/crates/doc/src/story.rs b/crates/doc/src/story.rsindex 68712b6f7..b68072c10 100644--- a/crates/doc/src/story.rs+++ b/crates/doc/src/story.rs@@ -272,9 +272,18 @@ impl Story {})}- /// Insert `text` at byte `pos` using the format at that position.+ /// The format text inserted at byte `pos` takes: the run before `pos`+ /// ([`Story::char_format_at`]), except on an empty paragraph, where it is that paragraph's own+ /// mark (the line's only character, so its format is the one chosen for that line).+ pub fn insert_format_at(&self, pos: usize) -> &CharFormat {+ let b = self.text.as_bytes();+ let empty_para = b.get(pos) == Some(&b'\n') && pos.checked_sub(1).and_then(|p| b.get(p)) == Some(&b'\n');+ if empty_para { self.format_after(pos) } else { self.char_format_at(pos) }+ }++ /// Insert `text` at byte `pos` using the format at that position ([`Story::insert_format_at`]).pub fn insert(&mut self, pos: usize, text: &str) {- let fmt = self.char_format_at(pos).clone();+ let fmt = self.insert_format_at(pos).clone();self.insert_with(pos, text, fmt);}@@ -392,7 +401,7 @@ impl Story {/// Replace a range with text (delete + insert using the format at the start of the range).pub fn replace(&mut self, range: std::ops::Range<usize>, text: &str) {- let fmt = if range.start < range.end { self.format_after(range.start).clone() } else { self.char_format_at(range.start).clone() };+ let fmt = if range.start < range.end { self.format_after(range.start).clone() } else { self.insert_format_at(range.start).clone() };self.delete(range.clone());self.insert_with(range.start, text, fmt);}diff --git a/crates/engine/src/cmd/text.rs b/crates/engine/src/cmd/text.rsindex a189c9620..66d06b57d 100644--- a/crates/engine/src/cmd/text.rs+++ b/crates/engine/src/cmd/text.rs@@ -614,7 +614,7 @@ fn insert(s: &mut Session, p: &Value) -> Result<Value> {if tracking && t.cell.is_none() {// Track Changes: the replaced text is marked deleted, the typing inserted after it.let at = super::changes::mark_deleted(st, r.clone());- let mut fmt = st.char_format_at(at).clone();+ let mut fmt = st.insert_format_at(at).clone();if let Some(f) = &typing {apply_typing_format(&mut fmt, f);}@@ -1295,7 +1295,8 @@ fn selection_attrs(s: &mut Session, _p: &Value) -> Result<Value> {/// inheritance separate from paragraph defaults for style creation from the selection.pub(crate) fn effective_char_format(s: &Session, target: &Target) -> Result<designcraft_doc::CharFormat> {let story = s.doc()?.doc.text_story(target.story, target.cell).ok_or(designcraft_doc::DocError::NoStory(target.story))?;- let mut format = if target.range.is_empty() { story.char_format_at(target.range.start) } else { story.format_after(target.range.start) }.clone();+ let mut format =+ if target.range.is_empty() { story.insert_format_at(target.range.start) } else { story.format_after(target.range.start) }.clone();if let Some(pending) = typing_format(s)&& target.story == pending.at.story&& target.cell == pending.at.cell@@ -1892,6 +1893,29 @@ What's new in typography this season, and why it matters to every designer"}),}assert_eq!(st.format_after(blank - 1).over.size, None, "the first paragraph's mark keeps its size");}++ /// A blank line keeps its format for typing after the caret has left it: text typed on it+ /// takes its paragraph mark's format, with no pending typing format.+ #[test]+ fn a_blank_lines_mark_format_is_typed_after_the_caret_returns() {+ let mut s = Session::new();+ s.execute("file.new", &json!({})).unwrap();+ let text = "Para one\n\nPara two";+ let r = s.execute("frame.create", &json!({"rect": [72, 72, 300, 200], "content": "text", "text": text})).unwrap();+ let sid = designcraft_doc::StoryId(r["story"].as_u64().unwrap());+ let blank = text.find("\n\n").unwrap() + 1;+ s.execute("text.select", &json!({"story": sid.0, "anchor": blank})).unwrap();+ s.execute("type.char", &json!({"attrs": {"size": 30}})).unwrap();+ s.execute("text.select", &json!({"story": sid.0, "anchor": 2})).unwrap();+ s.execute("text.select", &json!({"story": sid.0, "anchor": blank})).unwrap();+ assert!(s.typing_format.is_none());+ s.execute("text.insert", &json!({"text": "Middle"})).unwrap();+ let st = s.doc().unwrap().doc.story(sid).unwrap();+ assert_eq!(st.text, "Para one\nMiddle\nPara two");+ assert_eq!(st.format_after(blank).over.size, Some(30.0));+ assert_eq!(st.format_after(blank - 1).over.size, None, "the first paragraph's mark keeps its size");+ assert_eq!(st.format_after(2).over.size, None);+ }}#[cfg(test)]