Skip to content

Commit

Permalink
Improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
theolampert committed Oct 28, 2024
1 parent 03b09fd commit 2ed3d49
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ An (incomplete) Swift implementation of operation-based CRDTs for rich text edit

## Features

- Conflict-free collaborative text editing
- Support for basic text operations (insert/delete)
- Rich text formatting (bold, italic, underline)
- Automatic merging of concurrent edits
Expand All @@ -16,46 +15,46 @@ An (incomplete) Swift implementation of operation-based CRDTs for rich text edit

```swift
// Initialize with a unique user ID
let quilt = Quilt(user: UUID())
let doc = Quilt(user: UUID())

// Insert characters
quilt.insert(character: "H", atIndex: 0)
quilt.insert(character: "i", atIndex: 1)
doc.insert(character: "H", atIndex: 0)
doc.insert(character: "i", atIndex: 1)

// Remove characters
quilt.remove(atIndex: 1) // Removes "i"
doc.remove(atIndex: 1) // Removes "i"
```

### Text Formatting

```swift
// Add some text
quilt.insert(character: "H", atIndex: 0)
quilt.insert(character: "e", atIndex: 1)
quilt.insert(character: "l", atIndex: 2)
quilt.insert(character: "l", atIndex: 3)
quilt.insert(character: "o", atIndex: 4)
doc.insert(character: "H", atIndex: 0)
doc.insert(character: "e", atIndex: 1)
doc.insert(character: "l", atIndex: 2)
doc.insert(character: "l", atIndex: 3)
doc.insert(character: "o", atIndex: 4)

// Apply bold formatting to the entire word
quilt.addMark(mark: .bold, fromIndex: 0, toIndex: 4)
doc.addMark(mark: .bold, fromIndex: 0, toIndex: 4)

// Remove bold formatting
quilt.removeMark(mark: .bold, fromIndex: 0, toIndex: 4)
doc.removeMark(mark: .bold, fromIndex: 0, toIndex: 4)
```

### Collaborative Editing

```swift
var quilt1 = Quilt(user: UUID())
var quilt2 = Quilt(user: UUID())
var doc1 = Quilt(user: UUID())
var doc2 = Quilt(user: UUID())

// Make changes in both instances
quilt1.insert(character: "A", atIndex: 0)
quilt2.insert(character: "B", atIndex: 0)
doc1.insert(character: "A", atIndex: 0)
doc2.insert(character: "B", atIndex: 0)

// Merge changes
quilt1.merge(quilt2)
quilt2.merge(quilt1)
doc1.merge(doc2)
doc2.merge(doc1)

// Both instances now have the same content
```
Expand Down

0 comments on commit 2ed3d49

Please sign in to comment.