operations property

Iterable<Operation> get operations

Returns a sequence of operations describing how to turn source into target.

Implementation

Iterable<Operation> get operations {
  if (_operations.isNotEmpty) return _operations;
  var sourceStart = 0, targetStart = 0;
  for (final block in matches) {
    final type =
        sourceStart < block.sourceStart && targetStart < block.targetStart
            ? OperationType.replace
            : sourceStart < block.sourceStart
                ? OperationType.delete
                : targetStart < block.targetStart
                    ? OperationType.insert
                    : null;

    if (type != null) {
      _operations.add(Operation(
        type,
        sourceStart: sourceStart,
        sourceEnd: block.sourceStart,
        targetStart: targetStart,
        targetEnd: block.targetStart,
      ));
    }
    sourceStart = block.sourceStart + block.length;
    targetStart = block.targetStart + block.length;
    if (block.length > 0) {
      _operations.add(Operation(
        OperationType.equal,
        sourceStart: block.sourceStart,
        sourceEnd: sourceStart,
        targetStart: block.targetStart,
        targetEnd: targetStart,
      ));
    }
  }
  return _operations;
}