From 08f9bcd2884d0ad7022100012adccf527c77f6aa Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Wed, 13 Sep 2023 10:31:12 +0800 Subject: [PATCH] chore: refactor attribute comparison in Delta class diff loop (#456) --- lib/src/core/document/text_delta.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/src/core/document/text_delta.dart b/lib/src/core/document/text_delta.dart index fb0a43793..5e45d35a4 100644 --- a/lib/src/core/document/text_delta.dart +++ b/lib/src/core/document/text_delta.dart @@ -327,15 +327,16 @@ class Delta extends Iterable { final retDelta = Delta(); final diffResult = diff_match_patch.diff(strings[0], strings[1]); + diff_match_patch.DiffMatchPatch().diffCleanupSemantic(diffResult); final thisIter = _OpIterator(this); final otherIter = _OpIterator(other); - for (var component in diffResult) { - var length = component.text.length; + for (final diff in diffResult) { + var length = diff.text.length; while (length > 0) { var opLength = 0; - switch (component.operation) { + switch (diff.operation) { case diff_match_patch.DIFF_INSERT: opLength = min(otherIter.peekLength(), length); retDelta.add(otherIter.next(opLength)); @@ -352,7 +353,7 @@ class Delta extends Iterable { ); final thisOp = thisIter.next(opLength); final otherOp = otherIter.next(opLength); - if (thisOp.attributes == otherOp.attributes) { + if (isAttributesEqual(thisOp.attributes, otherOp.attributes)) { retDelta.retain( opLength, attributes: invertAttributes(