From 1ac2a086940e7a41971f1f96a17f842bf1c19d94 Mon Sep 17 00:00:00 2001 From: Rudy Huang Date: Fri, 15 Nov 2024 16:46:29 +0800 Subject: [PATCH] Fix #1: Make Delta.diff check Map equality instead of reference equality --- lib/src/delta/delta.dart | 5 ++++- test/dart_quill_delta_test.dart | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/src/delta/delta.dart b/lib/src/delta/delta.dart index fc0527b..eeb01f0 100644 --- a/lib/src/delta/delta.dart +++ b/lib/src/delta/delta.dart @@ -348,6 +348,9 @@ class Delta { final thisIter = DeltaIterator(this); final otherIter = DeltaIterator(other); + bool isEqual(Object? a, Object? b) => + const DeepCollectionEquality.unordered().equals(a, b); + for (final component in diffResult) { var length = component.text.length; while (length > 0) { @@ -369,7 +372,7 @@ class Delta { ); final thisOp = thisIter.next(opLength); final otherOp = otherIter.next(opLength); - if (thisOp.data == otherOp.data) { + if (isEqual(thisOp.data, otherOp.data)) { retDelta.retain( opLength, diffAttributes(thisOp.attributes, otherOp.attributes), diff --git a/test/dart_quill_delta_test.dart b/test/dart_quill_delta_test.dart index a2208c6..c1fac9e 100644 --- a/test/dart_quill_delta_test.dart +++ b/test/dart_quill_delta_test.dart @@ -1250,6 +1250,13 @@ void main() { expect(a.diff(b), expected); }); + test('embed object match #2', () { + final a = Delta()..insert({'image': 'http://google.com'})..insert('\n'); + final b = Delta()..insert({'image': 'http://google.com'}); + final expected = Delta()..retain(1)..delete(1); + expect(a.diff(b), expected); + }); + test('embed object mismatch', () { final a = Delta() ..insert({