Editing Toolkit with branched documents
Use the Editing Toolkit to merge two versions of a document that were edited separately. Your application keeps the HTML of the document from the moment it was copied and passes it to Compare as the snapshot. Compare finds the changes made in each branch and merges one branch into the other: directly, as Track Changes suggestions, or as proposed changes for users to review in CKEditor 5.
The document on the left is the original. Branch A and branch B start as copies of it. Edit both branches in different ways, for example change a sentence in one of them and add a paragraph or a list item in the other. Then choose Merge to bring the changes made in branch B into branch A as Track Changes suggestions. Reset the demo to start over.
The edits made in branch A stay in place. Compare uses the original as the base: it finds the edits made in branch A since the copy, finds the changes made in branch B, and merges both, so only the changes from branch B are added.
Original The document before it was copied. Both branches start from it.
Branch A Edit this branch. It receives the changes made in branch B. It retains its own changes.
Branch B Edit this branch too. Its changes are merged into branch A.
- Merge a copy of a document back into the main version, for example after a draft was edited in a separate workspace or by another team.
- Bring back changes made outside your system. A user exported the document, edited the copy in another application, and other users kept editing the document in the meantime.
- Compare two versions that share a common base when neither of them is a snapshot taken in the current editing session.
The diagram shows the workflow:
- A copy of the document is made. Your application stores the document HTML. This is the common base of both branches.
- The copy becomes branch B. Another team edits it, another system holds it, or it leaves as an exported file.
- The document itself keeps being edited in the editor. This is branch A.
- Branch B comes back as HTML, converted first if it comes in another format.
- Your application passes the stored HTML and the branch B HTML to
computePatch()orcomputeChanges(). - Compare compares the stored HTML with the current document to find the edits made in branch A, compares it with branch B to find the changes to merge, and merges both. Edits made in different parts of the document are all kept. Where both branches changed the same words, the result contains both versions, so review it.
- Your application applies the changes directly, records them as Track Changes suggestions, or presents them for review as in the Proposing changes guide.
- The user reviews branch A.
const patch = documentCompare.computePatch( originalHtml, branchHtml, { asSuggestions: true } );
documentCompare.applyPatch( patch );The stored HTML carries no element IDs, so Compare pairs the elements by content. See the Using an HTML string as a snapshot section of the Comparing documents guide for details.
- The
DocumentCompareplugin with a license key, plusProposedChangesif users should review the changes before they are applied. See the Comparing documents and Proposing changes guides for setup. - The HTML of the document from the moment it was copied, stored by your application.
- The Track Changes integration if changes should be recorded as suggestions.