computeDiff method

List<DiffHunk> computeDiff(
  1. String oldText,
  2. String newText, {
  3. DiffAlgorithm algorithm = DiffAlgorithm.myers,
  4. int? contextLines,
})

Compute the diff between oldText and newText.

Returns a list of DiffHunks representing the changes. The algorithm parameter selects the diff strategy (currently Myers is the only fully implemented variant; the others fall back to Myers).

Implementation

List<DiffHunk> computeDiff(
  String oldText,
  String newText, {
  DiffAlgorithm algorithm = DiffAlgorithm.myers,
  int? contextLines,
}) {
  final ctx = contextLines ?? defaultContextLines;
  final oldLines = oldText.isEmpty ? <String>[] : oldText.split('\n');
  final newLines = newText.isEmpty ? <String>[] : newText.split('\n');

  final edits = _myersDiff(oldLines, newLines);
  return _editsToHunks(edits, oldLines, newLines, ctx);
}