Skip to content

Commit

Permalink
chore: refactor attribute comparison in Delta class diff loop (AppFlo…
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 authored Sep 13, 2023
1 parent 95e1119 commit 08f9bcd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/src/core/document/text_delta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,16 @@ class Delta extends Iterable<TextOperation> {

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));
Expand All @@ -352,7 +353,7 @@ class Delta extends Iterable<TextOperation> {
);
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(
Expand Down

0 comments on commit 08f9bcd

Please sign in to comment.