Delta(WIP)

A Delta contains a list of operations, which describe the changes to a document. There are three kinds of operations, insert, delete, and retain. The implementation of Delta is located in the lib-ot(shared-lib/lib-ot) crate.The format of Delta is JSON based, and is human readable, it can describe any rich text document, includes all text and formatting information.

The picture shown below is a UML diagram that describes the relations between these classes. We're going to explain them on by one.

file : delta.plantuml

DeltaIterator

DeltaCursor

DeltaBuilder

Operation

Operation contains three types, Insert, Delete, and Retain.

Insert

Insert operations have an insert key defined. A String value represents inserting text. an optional attributes key can be defined with an Object to describe additional formatting information. Formats can be changed by the retain operation.

Delete

Delete operations have a Number delete key defined representing the number of characters to delete.

Retain

Retain operations have a Number retain key defined representing the number of characters to keep An optional attributes key can be defined with an Object to describe formatting changes to the character range. A value of null in the attributes Object represents removal of that key.

OTString

The length of strings behaves differently in different languages. For example: [Dart] string's length is calculated with UTF-16 code units. The method [utf16_len] returns the length of a String in UTF-16 code units.

OTUtf16CodePointIterator

Attributes

Each operation can carry attributes. For example, the [RichTextAttributes] has a list of key/value attributes. Such as { bold: true, italic: true }.

Because [Operation] is generic over the T, so you must specify the T. For example, the [TextDelta] uses [PhantomAttributes] as the T. [PhantomAttributes] does nothing, just a phantom.

RichTextAttributes

PhantomAttributes

OperationTransform

https://en.wikipedia.org/wiki/Operational_transformation

Serde

Import and Export

Markdown

We can use a Markdown parser to import the document into AppFlowy or export the data to a Markdown file. AppFlowy uses Delta to represent the document content.

Last updated

Was this helpful?