canMergeWith method

  1. @override
bool canMergeWith(
  1. EditOperation other
)
override

Check if this operation can be merged with another (for grouping rapid edits)

Implementation

@override
bool canMergeWith(EditOperation other) {
  if (other is! DeleteOperation) return false;

  final timeDiff = other.timestamp.difference(timestamp).inMilliseconds.abs();
  if (timeDiff > 500) return false;

  if (text.contains('\n') || other.text.contains('\n')) return false;

  if (other.offset == offset - other.text.length) {
    return true;
  }

  if (other.offset == offset) {
    return true;
  }
  return false;
}