Fix getPositionDelta

pull/13/head
singerdmx 4 years ago
parent 92a975b28e
commit 0800c6cb34
  1. 2
      lib/utils/diff_delta.dart
  2. 29
      lib/widgets/controller.dart

@ -71,7 +71,7 @@ int getPositionDelta(Delta user, Delta actual) {
DeltaIterator actualItr = DeltaIterator(actual); DeltaIterator actualItr = DeltaIterator(actual);
int diff = 0; int diff = 0;
while (userItr.hasNext || actualItr.hasNext) { while (userItr.hasNext || actualItr.hasNext) {
int length = math.min(userItr.peekLength(), actualItr.peekLength()); final length = math.min(userItr.peekLength(), actualItr.peekLength());
Operation userOperation = userItr.next(length); Operation userOperation = userItr.next(length);
Operation actualOperation = actualItr.next(length); Operation actualOperation = actualItr.next(length);
if (userOperation.length != actualOperation.length) { if (userOperation.length != actualOperation.length) {

@ -57,18 +57,23 @@ class QuillController extends ChangeNotifier {
if (delta == null) { if (delta == null) {
_updateSelection(textSelection, ChangeSource.LOCAL); _updateSelection(textSelection, ChangeSource.LOCAL);
} else { } else {
Delta user = Delta() try {
..retain(index) Delta user = Delta()
..insert(data) ..retain(index)
..delete(len); ..insert(data)
int positionDelta = getPositionDelta(user, delta); ..delete(len);
_updateSelection( int positionDelta = getPositionDelta(user, delta);
textSelection.copyWith( _updateSelection(
baseOffset: textSelection.baseOffset + positionDelta, textSelection.copyWith(
extentOffset: textSelection.extentOffset + positionDelta, baseOffset: textSelection.baseOffset + positionDelta,
), extentOffset: textSelection.extentOffset + positionDelta,
ChangeSource.LOCAL, ),
); ChangeSource.LOCAL,
);
} catch (e) {
print ('getPositionDelta or getPositionDelta error: $e');
throw e;
}
} }
} }
notifyListeners(); notifyListeners();

Loading…
Cancel
Save