RichTextOt
Keep Alice's bold heading and Bob's new symbol in the same report.
Two hikers edit one report heading
Alice bolds the report heading while Bob appends the current trail symbol.
The report heading reads Eagle Creek. Alice makes the first word bold. Bob adds the trail symbol ▲ at the end. Neither has seen the other's edit.
A RichTextOt describes each edit as a walk along the text: keep some characters, insert new ones, or delete some, and attach formatting to what it keeps or inserts. Alice's edit says “keep 5 characters and make them bold.” Bob's says “keep 11 characters, then insert ▲.” The ranger station numbers both edits, and each copy rewrites the later one against the earlier, as JsonOt did for list positions. Bold does not change the text's length, so Bob's ▲ still lands after 11 characters.
Alice sees the bold heading as soon as she edits it; Bob sees his own addition too. They keep later edits aside and adjust each new note against work already in the report. The ranger's numbered reply confirms each edit.
Run the conflict
Alice and Bob act before either receives the other's note. Carol receives their notes too and checks that all three copies agree.
RichTextOt at Eagle Creek
Alice bolds the report heading while Bob appends the current trail symbol.
Merge rule OT for formatted text: each edit keeps, inserts, or deletes characters and can attach formatting, and each copy rewrites concurrent edits against the numbered history.
Alice
Report page Eagle Creek
Edit note Bold Eagle bold the first 5 characters
Bob
Report page Eagle Creek
Edit note Append marker add ▲ after the first 11 characters
Carol
Report page Eagle Creek
Edit note Observe the report No note in this race
- Eagle Creek
Run the worked example
Queue the hikers' notes together, or reset and send one at a time.
Enable JavaScript to run the race. The expected result remains in the lesson.
Ready: Eagle Creek
Read the result
The heading keeps its formatting and Bob's insertion remains.
Formatting adds transform rules
Like JsonOt, RichTextOt needs the ranger station to order edits and a correct transform rule for every pair of edit types. Formatting adds questions the rules must answer, such as whether text inserted inside a bold range becomes bold.
The next lesson, Claims, leaves editing behind: the hikers need one owner for the gate key, and only the ranger can decide.
Sources and implementation
Sources:
Watershed's rich_text_kernel
and
Watershed's rich_text.
Implementation: The demo calls rich_text.delta_retain, rich_text.delta_insert_text, rich_text_kernel.submit, rich_text_kernel.ack_local, rich_text_kernel.apply_remote, and rich_text_kernel.view
through the Gleam toolkit. The displayed client records and shared
view come from those kernel results.