1

I have been studying CRDTs and understand that they have been used to build collaborative editors, including Ritzy, TreeDoc, WOOT and Logoot.

I'm interested in building such an editor, and need to know if CRDTs are known to be able to handle this problem in its generality.

To elaborate: A rich text document (think html) has a tree structure, but the nodes are heterogeneous. There are block elements, inline elements, tables, lists and so on. Further, there may be styles and stylesheets (e.g. css) embedded in a document. Finally, undo is essential.

The editors listed above do not handle the more advanced features, such as tables, embedded stylesheets and undo/redo.

The Ritzy documentation links to a paper describing CRDT-based causal trees (pdf) but I don't really understand this paper.

What is the basic principle behind a causal tree CRDT? Is it powerful enough to handle the heterogeneous trees described above? Alternatively, are there other CRDTs that could handle this scenario?

bright
  • 4,700
  • 1
  • 34
  • 59

1 Answers1

2

The implementation of a CRDT for rich-text is not very straight forward. Some CRDTs can be used to build trees. So the naive approach for rich-text would be to build it as a tree. A node would then represent a block of text with formats such as 'italic'. In order to format text, you usually have to delete it, and insert a new node with that format. But this does not always work as expected: For example, if two users concurrently format the same text, the formatted text is inserted two times after convergence (User1 deletes text, and inserts a new node. User2 deletes the same text, and inserts a new node). To my knowledge there are no CRDTs that solve this problem.

Actually a CRDT for linear structure does completely suffice. You can realize formats as markers (i.e. format start, and format end). This also has the advantage that you get the expected result when two users concurrently format/insert text.

For a working implementation of this approach you can check out Yjs. The examples section contains a working example of a rich text editor.

(Full disclosure: I am the author of Yjs)

dmonad
  • 618
  • 5
  • 10