Skip to main content

write_revert_patches

Function write_revert_patches 

pub fn write_revert_patches(
    doc: &mut AutoCommit,
    from_heads: &[ChangeHash],
    to_heads: &[ChangeHash],
)
Expand description

Write the delta that leads from from_heads to to_heads into doc’s open transaction, without committing.

The one primitive behind both undo and restore-from-history: it re-derives exactly the properties and elements that differ and writes them forward, rather than replacing the document with an old state and dropping every concurrently-merged remote op. A container the delta would remove that somebody has written inside since from_heads — the paragraph a collaborator typed into after the action that created it — is left standing, so undo takes back only the action.

The caller commits. That is deliberate: the owner’s action records the restore, so it lands on the undo stack with the right author and timestamp exactly like any other edit. State::restore_to_heads is the equivalent for a host that owns a whole State.