From 4c1ae401bb71cfa0a6edaa033470ab27cce80106 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 13 Nov 2026 19:23:47 +0000 Subject: changes: an insert may follow a mark the document holds Screening asked of every operation naming an element that the element was inserted as a value or an object, inserting or not. In a document that took a mark before marks were refused, a transaction typing right after it inserts after the mark's begin or end, and was refused: every node refused the change of the node that typed, and all it wrote after. An element is written at only where a value or an object was put; an insert may follow any element of that list, as transactions insert. --- src/document/changes.rs | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/document/changes.rs b/src/document/changes.rs index bb448e0..51f9f6f 100644 --- a/src/document/changes.rs +++ b/src/document/changes.rs @@ -537,14 +537,17 @@ impl Written { } } } - // The element of a list: a value or an object put into that list. + // The element of a list: one put into that list, and written at only where a + // value or an object was put (an insert may follow a mark's begin or end, + // in a document that holds one from before marks were refused). let element = match &op.key { Key::Seq(ElementId::Id(id)) => Some(id), Key::Seq(ElementId::Head) | Key::Map(_) => None, }; if let Some(id) = element - && !made(self, id) - .is_some_and(|made| made.insert && made.holds && made.obj == op.obj) + && !made(self, id).is_some_and(|made| { + made.insert && made.obj == op.obj && (op.insert || made.holds) + }) { let OpId(counter, by) = id; return Some(format!( @@ -1370,7 +1373,9 @@ mod tests { /// No mark: one a transaction writes, or one ended where nothing began. Automerge /// takes some marks and then breaks (a value written at a mark's begin or end, once - /// the text is edited; a mark ended ahead of its begin); continuum writes none. + /// the text is edited; a mark ended ahead of its begin); continuum writes none. In + /// a document that holds one from before, typing next to it passes, writing at it + /// doesn't. #[test] fn no_mark() { use crate::document::Transaction; @@ -1406,10 +1411,35 @@ mod tests { let ended = crafted(&typed, |change| { change.operations[0].action = OpType::MarkEnd(false) }); - for crafted in [marked, ended] { + for crafted in [marked.clone(), ended] { let why = Written::default().check(&ours, &crafted, &crafted.decode()); assert!(why.is_some(), "{:?}", crafted.decode().operations); } + // Taken without screening: "a" marked, its begin after the head, its end after + // "a". + let mut held = ours.fork(); + held.apply_changes([marked.clone()]).unwrap(); + for at in 0..=4 { + let typed = on(&held, |doc| doc.splice_text(&text, at, 0, "x").unwrap()); + assert_eq!( + Written::default().check(&held, &typed, &typed.decode()), + None, + "{:?}", + typed.decode().operations + ); + } + let begin = automerge::legacy::OpId(marked.start_op().get(), marked.actor_id().clone()); + let deleted = on(&held, |doc| doc.splice_text(&text, 0, 1, "").unwrap()); + let at_the_begin = crafted(&deleted, |change| { + change.operations[0].key = + automerge::legacy::Key::Seq(automerge::legacy::ElementId::Id(begin.clone())); + change.operations[0].pred = vec![begin.clone()].into(); + }); + assert!( + Written::default() + .check(&held, &at_the_begin, &at_the_begin.decode()) + .is_some() + ); } /// No table: made, by itself or with what is written into it, or written into -- cgit v1.3.1