I have see several bindings, for example that of the Quill, which is used as editor.
What I am looking for is understanding if there is any convenience function that could just diff the current state of the text editor with the current state of the Y.doc, given that for some interfaces you don’t have cursor actions, just knowing that text has been updated. I don’t want to figure out the insert, extends, etc. myself I would place my trust in some algorithm that figures that out for me. Obviously I want something better than the current map options where ‘last write wins’ is applied.
ORIGINAL = "Hello world" UPDATE = "Hello sir" ydoc_orig = YDoc() ydoc_update = YDoc() field_orig = ydoc_orig.get_text("fieldname") with ydoc_orig.begin_transaction() as txn: field_orig.insert(txn, 0, ORIGINAL) new = ydoc_update.get_text("fieldname") with ydoc_update.begin_transaction() as txn: new.insert(txn, 0, UPDATE) # state_vector_update = encode_state_vector(ydoc_update) # diff_update = encode_state_as_update(ydoc_orig, state_vector_update) diff_update = encode_state_as_update(ydoc_update) apply_update(ydoc_orig, diff_update) print(ydoc_orig.get_text('fieldname').to_json())
The result of the above is “Hello worldHello sir”, so is there a way that would create a delete for world, and an insert for sir?