DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Merge tested main 26137acbb251 into PR #456
sanyamsingh001b20a94aa6a10
diff --cc crates/doc/src/slice.rsindex 58d35cd80,d4a80e53f..f9637e524--- a/crates/doc/src/slice.rs+++ b/crates/doc/src/slice.rs@@@ -116,15 -124,14 +124,14 @@@ impl Storylet mut t = (**t).clone();t.id = next;next += 1;+ claims.push((pos + r.start + k, t.id));self.tables.insert(t.id, Arc::new(t));- if let Some(p) = self.paras.get_mut(pi) {- p.table = Some(next - 1);- }}- self.fix_tables();}+ let splits = self.fix_tables_with(&claims);- self.rev += 1;+ self.rev = self.rev.wrapping_add(1);- end+ // Past any return the fix-up put inside the pasted text.+ end + splits.iter().filter(|&&s| s < end).count()}/// Append the whole of `other` as new paragraphs after this story's text (threading twodiff --cc crates/doc/src/story.rsindex 4669bda07,68712b6f7..d868bfed9--- a/crates/doc/src/story.rs+++ b/crates/doc/src/story.rs@@@ -345,8 -386,8 +386,8 @@@ impl Storyself.text.replace_range(a..b, "");self.remove_run_bytes(a, b - a);self.normalize();- self.fix_tables();+ self.fix_tables_with(&claims);- self.rev += 1;+ self.rev = self.rev.wrapping_add(1);}/// Replace a range with text (delete + insert using the format at the start of the range).diff --cc crates/engine/src/cmd/linked.rsindex ab53837b0,121ad2a9d..0b80e3aab--- a/crates/engine/src/cmd/linked.rs+++ b/crates/engine/src/cmd/linked.rs@@@ -11,8 -11,8 +11,8 @@@ use crate::Resultfn copy_into(d: &mut Document, parent: StoryId, child: StoryId) -> Result<()> {let src = d.story(parent).ok_or_else(|| bad("story.link", format!("no story {}", parent.0)))?.clone();let st = d.story_mut(child).ok_or_else(|| bad("story.link", format!("no story {}", child.0)))?;- let (frames, rev) = (std::mem::take(&mut st.frames), st.rev);- *st = Story { id: child, frames, rev: rev.wrapping_add(1), link: Some((parent, src.rev)), ..src };+ let (frames, rev, file_link) = (std::mem::take(&mut st.frames), st.rev, st.file_link.take());- *st = Story { id: child, frames, rev: rev + 1, link: Some((parent, src.rev)), file_link, ..src };++ *st = Story { id: child, frames, rev: rev.wrapping_add(1), link: Some((parent, src.rev)), file_link, ..src };Ok(())}diff --cc crates/engine/src/cmd/text.rsindex b3364f462,fd5de519c..7b1432ca5--- a/crates/engine/src/cmd/text.rs+++ b/crates/engine/src/cmd/text.rs@@@ -1071,12 -1128,21 +1128,21 @@@ pub(crate) fn apply_char_attrs(d: &mutlet r = &t.range;let Some(st) = d.text_story_mut(t.story, t.cell) else { continue };if r.is_empty() {- // An empty story: its one (empty) run is the format typing takes.- if st.is_empty()- && let Some(run) = st.chars.first_mut()- {- run.format.over.merge(a);- st.rev = st.rev.wrapping_add(1);+ if st.is_empty() {+ // An empty story: its one (empty) run is the format typing takes.+ if let Some(run) = st.chars.first_mut() {+ run.format.over.merge(a);- st.rev += 1;++ st.rev = st.rev.wrapping_add(1);+ }+ } else if empty_para_mark(st, r.start) {+ // An empty paragraph elsewhere in the story: its hidden paragraph mark is its only+ // character, and the one that carries line-affecting attributes like leading.+ st.format_chars(r.start..r.start + 1, |f| {+ f.over.merge(a);+ for k in cleared {+ let _ = f.over.set_json(k, &Value::Null);+ }+ });}continue;}diff --cc crates/engine/tests/thread_color_safety.rsindex 1457d01c1,501df92b9..58f2368a0--- a/crates/engine/tests/thread_color_safety.rs+++ b/crates/engine/tests/thread_color_safety.rs@@@ -221,56 -221,3 +221,57 @@@ fn safety_empty_linked_parent_follows_s}}}++#[test]+fn safety_thread_revision_wrap_keeps_link_stale_through_native_reopen() {+ let mut s = setup();+ let (first, survivor) = frame(&mut s, "PREFIX");+ let (incoming, parent) = frame(&mut s, "PARENT");+ // The copied parent's token will coincide with the merged survivor's final revision.+ Arc::make_mut(&mut s.doc_mut().unwrap().doc).story_mut(parent).unwrap().rev = 1;+ let (_, linked) = child(&mut s, parent);- Arc::make_mut(&mut s.doc_mut().unwrap().doc).story_mut(survivor).unwrap().rev = u64::MAX;+ assert_eq!(link(&mut s, linked)["outOfDate"], false);+ let bytes = s.execute("file.serialize", &json!({})).unwrap();+ let mut reopened = Session::new();+ reopened.execute("file.openBytes", &json!({"name":"rollover.designcraft","base64":bytes["base64"]})).unwrap();+ let mut s = reopened;++ // Inject the in-memory rollover boundary after load, independently of cold-load normalization.++ Arc::make_mut(&mut s.doc_mut().unwrap().doc).story_mut(survivor).unwrap().rev = u64::MAX;+ assert_eq!(s.doc().unwrap().doc.story(survivor).unwrap().rev, u64::MAX);+ assert_eq!(s.doc().unwrap().doc.story(linked).unwrap().link, Some((parent, 1)));+ let before = s.doc().unwrap().doc.clone();+ let child_frames = before.story(linked).unwrap().frames.clone();++ s.execute("text.thread", &json!({"from":first,"to":incoming})).unwrap();+ let d = &s.doc().unwrap().doc;+ let st = d.story(survivor).unwrap();+ assert_eq!(st.rev, 1, "append wraps MAX to 0, then threading increments to 1");+ assert_eq!(st.text, "PREFIX\nPARENT");+ assert_eq!(st.frames, [designcraft_doc::ItemId(first), designcraft_doc::ItemId(incoming)]);+ assert!(d.story(parent).is_none());+ assert_eq!(d.story(linked).unwrap().link, Some((survivor, 0)));+ assert_eq!(d.story(linked).unwrap().text, "PARENT");+ assert_eq!(d.story(linked).unwrap().frames, child_frames);+ d.check().unwrap();+ let after = d.clone();+ assert_eq!(link(&mut s, linked)["outOfDate"], true);++ let bytes = s.execute("file.serialize", &json!({})).unwrap();+ let mut reopened = Session::new();+ reopened.execute("file.openBytes", &json!({"name":"merged-rollover.designcraft","base64":bytes["base64"]})).unwrap();+ assert_eq!(reopened.doc().unwrap().doc.story(survivor).unwrap().rev, 1);+ assert_eq!(reopened.doc().unwrap().doc.story(linked).unwrap().link, Some((survivor, 0)));+ assert_eq!(link(&mut reopened, linked)["outOfDate"], true);+ reopened.execute("story.updateLink", &json!({"story":linked.0})).unwrap();+ let st = reopened.doc().unwrap().doc.story(linked).unwrap();+ assert_eq!(st.id, linked);+ assert_eq!(st.frames, child_frames);+ assert_eq!(st.text, "PREFIX\nPARENT");+ assert_eq!(st.link, Some((survivor, 1)));+ assert_eq!(link(&mut reopened, linked)["outOfDate"], false);++ s.execute("edit.undo", &json!({})).unwrap();+ assert_eq!(s.doc().unwrap().doc, before);+ s.execute("edit.redo", &json!({})).unwrap();+ assert_eq!(s.doc().unwrap().doc, after);+}