mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: add cache to text_delta
This commit is contained in:
parent
737e374a54
commit
eb519f4e11
@ -259,6 +259,7 @@ TextOperation? _textOperationFromJson(Map<String, dynamic> json) {
|
|||||||
// basically copy from: https://github.com/quilljs/delta
|
// basically copy from: https://github.com/quilljs/delta
|
||||||
class Delta extends Iterable<TextOperation> {
|
class Delta extends Iterable<TextOperation> {
|
||||||
final List<TextOperation> _operations;
|
final List<TextOperation> _operations;
|
||||||
|
String? _rawString;
|
||||||
|
|
||||||
factory Delta.fromJson(List<dynamic> list) {
|
factory Delta.fromJson(List<dynamic> list) {
|
||||||
final operations = <TextOperation>[];
|
final operations = <TextOperation>[];
|
||||||
@ -284,6 +285,7 @@ class Delta extends Iterable<TextOperation> {
|
|||||||
if (textOp.isEmpty) {
|
if (textOp.isEmpty) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
_rawString = null;
|
||||||
|
|
||||||
if (_operations.isNotEmpty) {
|
if (_operations.isNotEmpty) {
|
||||||
final lastOp = _operations.last;
|
final lastOp = _operations.last;
|
||||||
@ -431,6 +433,7 @@ class Delta extends Iterable<TextOperation> {
|
|||||||
if (_operations.isEmpty) {
|
if (_operations.isEmpty) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
_rawString = null;
|
||||||
final lastOp = _operations.last;
|
final lastOp = _operations.last;
|
||||||
if (lastOp is TextRetain && (lastOp.attributes?.length ?? 0) == 0) {
|
if (lastOp is TextRetain && (lastOp.attributes?.length ?? 0) == 0) {
|
||||||
_operations.removeLast();
|
_operations.removeLast();
|
||||||
@ -481,9 +484,11 @@ class Delta extends Iterable<TextOperation> {
|
|||||||
return _operations.map((e) => e.toJson()).toList();
|
return _operations.map((e) => e.toJson()).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: It's unneccesry to compute everytime.
|
String toRawString() {
|
||||||
String toRawString() =>
|
_rawString ??=
|
||||||
_operations.whereType<TextInsert>().map((op) => op.content).join();
|
_operations.whereType<TextInsert>().map((op) => op.content).join();
|
||||||
|
return _rawString!;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Iterator<TextOperation> get iterator => _operations.iterator;
|
Iterator<TextOperation> get iterator => _operations.iterator;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user