@@ -470,10 +470,20 @@ class Delta {
470470 return _operations.map <T >(f);
471471 }
472472
473- /// Returns a [Delta] containing differences between 2 [Delta] s
473+ /// Returns a [Delta] containing differences between 2 [Delta] s.
474+ /// If [cleanupSemantic] is `true` (default), applies the following:
475+ ///
476+ /// The diff of "mouse" and "sofas" is
477+ /// [delete(1), insert("s"), retain(1),
478+ /// delete("u"), insert("fa"), retain(1), delete(1)].
479+ /// While this is the optimum diff, it is difficult for humans to understand.
480+ /// Semantic cleanup rewrites the diff,
481+ /// expanding it into a more intelligible format.
482+ /// The above example would become: [(-1, "mouse"), (1, "sofas")] .
483+ /// (source: https://github.com/google/diff-match-patch/wiki/API)
474484 ///
475485 /// Useful when one wishes to display difference between 2 documents
476- Delta diff (Delta other) {
486+ Delta diff (Delta other, { bool cleanupSemantic = true } ) {
477487 if (_operations.equals (other._operations)) {
478488 return Delta ();
479489 }
@@ -494,6 +504,10 @@ class Delta {
494504
495505 final retDelta = Delta ();
496506 final diffResult = dmp.diff (stringThis, stringOther);
507+ if (cleanupSemantic) {
508+ dmp.DiffMatchPatch ().diffCleanupSemantic (diffResult);
509+ }
510+
497511 final thisIter = DeltaIterator (this );
498512 final otherIter = DeltaIterator (other);
499513
0 commit comments