Peritext: A CRDT for Collaborative Rich Text Editing

Geoffrey Litt, Sarah Lim, Martin Kleppmann and Peter van Hardenberg

Abstract

Conflict-Free Replicated Data Types (CRDTs) support decentralized collaborative editing of shared data, enabling peer-to-peer sharing and flexible branching and merging workflows. While there is extensive work on CRDTs for plain text, much less is known about CRDTs for rich text with formatting. No algorithms have been published, and existing open-source implementations do not always preserve user intent. In this paper, we describe a model of intent preservation in rich text editing, developed through a series of concurrent editing scenarios. We then describe Peritext, a CRDT algorithm for rich text that satisfies the criteria of our model. The key idea is to store formatting spans alongside the plaintext character sequence, linked to a stable identifier for the first and last character of each span, and then to derive the final formatted text from these spans in a deterministic way that ensures concurrent operations commute. We have prototyped our algorithm in TypeScript, validated it using randomized property-based testing, and integrated it with an editor UI. We also prove that our algorithm ensures convergence, and demonstrate its causality preservation and intention preservation properties.

Venue
CSCW 2022
Volume
Proceedings of the ACM on Human-Computer Interaction, Volume 6, Issue CSCW2
DOI
10.1145/3555644
PDF
https://dl.acm.org/doi/pdf/10.1145/3555644
Anthology ID
2022.pacm-cscw2.256

Cite

@article{litt-etal-2022-peritext,
    title = {{Peritext: A CRDT for Collaborative Rich Text Editing}},
    author = {Geoffrey Litt and Sarah Lim and Martin Kleppmann and Peter van Hardenberg},
    journal = {Proceedings of the ACM on Human-Computer Interaction},
    volume = {6},
    number = {CSCW2},
    issn = {2573-0142},
    year = {2022},
    publisher = {Association for Computing Machinery},
    address = {New York, NY, USA},
    doi = {10.1145/3555644},
    url = {https://doi.org/10.1145/3555644},
    abstract = {Conflict-Free Replicated Data Types (CRDTs) support decentralized collaborative editing of shared data, enabling peer-to-peer sharing and flexible branching and merging workflows. While there is extensive work on CRDTs for plain text, much less is known about CRDTs for rich text with formatting. No algorithms have been published, and existing open-source implementations do not always preserve user intent. In this paper, we describe a model of intent preservation in rich text editing, developed through a series of concurrent editing scenarios. We then describe Peritext, a CRDT algorithm for rich text that satisfies the criteria of our model. The key idea is to store formatting spans alongside the plaintext character sequence, linked to a stable identifier for the first and last character of each span, and then to derive the final formatted text from these spans in a deterministic way that ensures concurrent operations commute. We have prototyped our algorithm in TypeScript, validated it using randomized property-based testing, and integrated it with an editor UI. We also prove that our algorithm ensures convergence, and demonstrate its causality preservation and intention preservation properties.}
}