History

In the engine, the observe method of MutationObserver is used to monitor the changes of the DOM tree. The observe method is not triggered immediately after every change, but in Triggered when there is no subsequent editing behavior. This interval is very short, so short that we can think of it as changing from time to time. This interval depends on the implementation of MutationObserver and we cannot control it.

For each change, we will provide the DOM node data (similar to addition, deletion and modification operations) provided to us by MutationObserver, including attribute changes. Converting to Ops is equivalent to a set of description operations, and secondly, we also record before the change The cursor position. We treat these data as a kind of snapshot in the memory in the form of a stack. When executing undo and redo commands, we will search and restore by index from this stack. At the same time, these operations will also be transmitted to our collaborative server to notify each client of the changes in the DOM tree