Skip to main content

compose

Function compose 

Source
pub fn compose(a: &[Change], b: &[Change]) -> Vec<Change>
Expand description

A change list apply-equivalent to running a then b.

Because apply folds changes in order against the live tree, b’s paths/indices already assume a has run — so plain concatenation is the semantic identity. compose returns that concatenation in compacted form (redundant node-local ops coalesced).

use tiptap_rusty_parser::{apply, compose, Node};
let base = Node::element("doc").with_child(Node::text("x"));
let a = vec![tiptap_rusty_parser::Change::SetText { path: vec![0], text: Some("y".into()) }];
let b = vec![tiptap_rusty_parser::Change::SetText { path: vec![0], text: Some("z".into()) }];
let composed = compose(&a, &b);
assert_eq!(composed.len(), 1); // the two SetTexts coalesced to the last
let mut t = base.clone();
apply(&mut t, &composed).unwrap();
assert_eq!(t.text_content(), "z");