transformOperation function
Implementation
Operation? transformOperation(Operation a, Operation b) {
if (a is InsertOperation) {
final newPath = transformPath(a.path, b.path, a.nodes.length);
return b.copyWith(path: newPath);
} else if (a is DeleteOperation) {
if (b is DeleteOperation) {
if (a.path.isParentOf(b.path)) {
return null; // a is parent of b, we can just delete a and ignore b.
} else if (b.path.isParentOf(a.path)) {
return a.copyWith(path: b.path);
}
}
final newPath = transformPath(a.path, b.path, -1 * a.nodes.length);
return b.copyWith(path: newPath);
}
return b;
}