A Go port of the Rust operational-transform library, which itself is a port of ot.js.
Operational Transformation (OT) is an algorithm for supporting real-time collaborative editing in distributed systems. It enables multiple users to concurrently edit the same document while maintaining consistency across all copies, without using locks or requiring users to wait for each other.
- ✅ Direct port from Rust - Maintains identical behavior to the battle-tested Rust implementation
- ✅ UTF-8 character handling - Correctly counts Unicode codepoints (not bytes)
- ✅ JSON wire format compatibility - Compatible with Rust and JavaScript implementations
- ✅ Complete test coverage - All tests ported from Rust pass
- ✅ Type-safe operations - Go's type system prevents invalid operations
go get github.com/shiv248/operational-transformation-goThree basic operations:
- Retain(n): Move cursor forward n positions without changing anything
- Delete(n): Delete n characters at current position
- Insert(s): Insert string at current position
import "github.com/shiv248/operational-transformation-go"
// Create operations
op := ot.NewOperationSeq()
op.Retain(5)
op.Insert("world")
op.Delete(3)
// Apply to text
result, err := op.Apply("hello123")
// result = "helloworld"
// Transform concurrent operations
a := ot.NewOperationSeq()
a.Insert("A")
b := ot.NewOperationSeq()
b.Insert("B")
aPrime, bPrime, err := a.Transform(b)
// Both clients converge to same result
// Compose sequential operations
c, err := a.Compose(b)
// c = single operation equivalent to a followed by b
// Invert for undo
inverse := op.Invert("original text")Compatible with Rust/JavaScript wire format:
import "encoding/json"
op := ot.NewOperationSeq()
op.Retain(1)
op.Delete(1)
op.Insert("abc")
data, _ := json.Marshal(op)
// data = [1, -1, "abc"]
var op2 ot.OperationSeq
json.Unmarshal(data, &op2)go test ./...All tests ported from Rust operational-transform pass successfully.
- Kolabpad - Real-time collaborative editor using this library
- OT.js Demo - Interactive visualization of Operational Transformation
Contributions are welcome! Please feel free to submit a Pull Request. For major changes:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes using Conventional Commits
- Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Rust operational-transform - Source for this Go port
- ot.js - Original JavaScript implementation
- OT FAQ - Comprehensive FAQ on Operational Transformation
- Sun, C., & Ellis, C. (1998). Operational transformation in real-time group editors. CSCW '98, 59-68.
- Foundational paper on OT theory and algorithms
MIT - Same as the Rust and JavaScript implementations. See LICENSE and NOTICE for details.