Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Peritext-like rich text support #123

Merged
merged 57 commits into from
Oct 29, 2023
Merged

Feat: Peritext-like rich text support #123

merged 57 commits into from
Oct 29, 2023

Conversation

zxch3n
Copy link
Member

@zxch3n zxch3n commented Oct 18, 2023

This PR implements a new rich text CRDT algorithm that is greatly inspired by Peritext.

It behaves just like Peritext when editing locally. The behavior only differ when there is concurrent insertion at the style boundaries.

It satisfies the requirements listed in Peritext paper Chapter 3 "CRITERIA FOR INTENT PRESERVATION". Specifically, it passes all the following tests besides the consistency fuzzing tests.

Richtext Test Cases

0. Insert into bold span

Name Text
Origin Hello World
Concurrent A <b>Hello World</b>
Concurrent B Hello New World
Expected Result <b>Hello New World</b>

1. Merge Concurrent Styles

Name Text
Origin Hello World
Concurrent A <b>Hello</b> World
Concurrent B Hel<b>lo World</b>
Expected Result <b>Hello World</b>

2. Concurrent insert text & remove style

Name Text
Origin <b>Hello World</b>
Concurrent A Hello <b>World</b>
Concurrent B <b>Hello a World</b>
Expected Result Hello a <b>World</b>

3. Concurrent insert text & style

Name Text
Origin Hello World
Concurrent A Hello <b>World</b>
Concurrent B Hello a World
Expected Result Hello a <b>World</b>

4. Concurrently insert text and style that expands

This doesn't work well in our implementation

Name Text
Origin Hello World
Concurrent A <b>Hello</b> World
Concurrent B Hello* World
Expected Result <b>Hello*</b> World

5. Concurrent text edit & style that shrink

Name Text
Origin Hello World
Concurrent A <link>Hello</link> World
Concurrent B Hey World
Expected Result <link>Hey</link> World

6. Local insertion expand rules

Hello World

When insert a new character after "Hello", the new char should be bold but not link

Hellot World

Name Text
Origin <b><link>Hello</link><b> World
Expected Result <b><link>Hello</link>t<b> World

7. Concurrent unbold

In Peritext paper 2.3.2

Name Text
Origin <b>The fox jumped</b> over the dog.
Concurrent A The fox jumped over the dog.
Concurrent B <b>The </b>fox<b> jumped</b> over the dog.
Expected Result The fox jumped over the dog.

8. Bold & Unbold

In Peritext paper 2.3.3

Name Text
Origin <b>The fox jumped</b> over the dog.
Concurrent A <b>The fox</b> jumped over the dog.
Concurrent B <b>The</b> fox jumped over the <b>dog</b>.
Expected Result <b>The</b> fox jumped over the <b>dog</b>.

9. Overlapped formatting

In Peritext paper 3.2, example 3

Name Text
Origin The fox jumped.
Concurrent A The fox jumped.
Concurrent B The fox jumped.
Expected Result The fox jumped.

10. Multiple instances of the same mark

@zxch3n zxch3n requested a review from Leeeon233 October 18, 2023 07:02
@zxch3n zxch3n added enhancement New feature or request refactor labels Oct 18, 2023
@zxch3n zxch3n self-assigned this Oct 18, 2023
@zxch3n zxch3n changed the title Feat: richtext & a bunch of refactoring Feat: Peritext-like Rich Text Oct 28, 2023
@zxch3n zxch3n changed the title Feat: Peritext-like Rich Text Feat: Peritext-like rich text support Oct 28, 2023
crates/loro-common/src/lib.rs Show resolved Hide resolved
crates/loro-internal/Cargo.toml Outdated Show resolved Hide resolved
crates/loro-internal/benches/text_r.rs Show resolved Hide resolved
use append_only_bytes::{AppendOnlyBytes, BytesSlice};

use crate::container::richtext::richtext_state::unicode_to_utf8_index;
const INDEX_INTERVAL: u32 = 128;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the meaning of INDEX_INTERVAL?

@zxch3n zxch3n merged commit d942e3d into main Oct 29, 2023
1 check passed
@zxch3n zxch3n deleted the feat-richtext branch December 5, 2023 03:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants