Rich text / foldkit-richtext-dom/editor-bundle
patchTo
function · packages/richtext-dom/src/editor-bundle.ts:363
function patchTo(
hostId: string,
previous: RichText.Document,
next: RichText.EditorState,
): Command.Command<Message>Patches the editor at hostId to next, a document the parent put in place of
previous, keeping the host element instead of mounting a new one. A parent that
replaces its document outside an edit here (another replica's change arriving) returns
this, in the same transition as the replacement.
The host is found by the document the view renders, so previous is the object it
rendered and next.document the object it will render; building the Command hands the
host on from one to the other, so build it only to return it. The patch itself starts
from the latest state the editor holds (what it has drawn, or a state waiting on a
composition), and next.selection becomes the browser selection;
a replacement that changes nothing drawn leaves the DOM alone, selection included, as an
exchange that only confirms edits already shown does.