Skip to content

Commit

Permalink
Fix #1: Make Delta.diff check Map equality instead of reference equality
Browse files Browse the repository at this point in the history
  • Loading branch information
scribetw committed Nov 15, 2024
1 parent 500a0f8 commit 1ac2a08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/src/delta/delta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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),
Expand Down
7 changes: 7 additions & 0 deletions test/dart_quill_delta_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 1ac2a08

Please sign in to comment.