Skip to content

Commit 3b4e5d8

Browse files
committed
Replaced double.infinity with DeltaIterator.maxLength
1 parent 138d89e commit 3b4e5d8

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

lib/src/models/quill_delta.dart

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ class Delta {
551551
var index = 0;
552552
final opIterator = DeltaIterator(this);
553553

554-
final actualEnd = end ?? double.infinity;
554+
final actualEnd = end ?? DeltaIterator.maxLength;
555555

556556
while (index < actualEnd && opIterator.hasNext) {
557557
Operation op;
@@ -602,10 +602,12 @@ class Delta {
602602
class DeltaIterator {
603603
DeltaIterator(this.delta) : _modificationCount = delta._modificationCount;
604604

605+
static const int maxLength = 1073741824;
606+
605607
final Delta delta;
606608
final int _modificationCount;
607609
int _index = 0;
608-
num _offset = 0;
610+
int _offset = 0;
609611

610612
bool get isNextInsert => nextOperationKey == Operation.insertKey;
611613

@@ -621,24 +623,31 @@ class DeltaIterator {
621623
}
622624
}
623625

624-
bool get hasNext => peekLength() < double.infinity;
626+
bool get hasNext => peekLength() < maxLength;
625627

626628
/// Returns length of next operation without consuming it.
627629
///
628-
/// Returns [double.infinity] if there is no more operations left to iterate.
629-
num peekLength() {
630+
/// Returns [maxLength] if there is no more operations left to iterate.
631+
int peekLength() {
630632
if (_index < delta.length) {
631633
final operation = delta._operations[_index];
632634
return operation.length! - _offset;
633635
}
634-
return double.infinity;
636+
return maxLength;
635637
}
636638

637639
/// Consumes and returns next operation.
638640
///
639641
/// Optional [length] specifies maximum length of operation to return. Note
640642
/// that actual length of returned operation may be less than specified value.
641-
Operation next([int length = 4294967296]) {
643+
///
644+
/// If this iterator reached the end of the Delta then returns a retain
645+
/// operation with its length set to [maxLength].
646+
// TODO: Note that we used double.infinity as the default value for length here
647+
// but this can now cause a type error since operation length is
648+
// expected to be an int. Changing default length to [maxLength] is
649+
// a workaround to avoid breaking changes.
650+
Operation next([int length = maxLength]) {
642651
if (_modificationCount != delta._modificationCount) {
643652
throw ConcurrentModificationError(delta);
644653
}
@@ -656,13 +665,13 @@ class DeltaIterator {
656665
_offset += actualLength;
657666
}
658667
final opData = op.isInsert && op.data is String
659-
? (op.data as String).substring(
660-
_currentOffset as int, _currentOffset + (actualLength as int))
668+
? (op.data as String)
669+
.substring(_currentOffset, _currentOffset + actualLength)
661670
: op.data;
662671
final opIsNotEmpty =
663672
opData is String ? opData.isNotEmpty : true; // embeds are never empty
664673
final opLength = opData is String ? opData.length : 1;
665-
final opActualLength = opIsNotEmpty ? opLength : actualLength as int;
674+
final opActualLength = opIsNotEmpty ? opLength : actualLength;
666675
return Operation._(opKey, opActualLength, opData, opAttributes);
667676
}
668677
return Operation.retain(length);

0 commit comments

Comments
 (0)