Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: compute string indexes
Vincent Chanbee1a0432936
diff --git a/frontend/app_flowy/packages/flowy_editor/lib/src/document/text_delta.dart b/frontend/app_flowy/packages/flowy_editor/lib/src/document/text_delta.dartindex 6626ba7a86..03ae4ccc56 100644--- a/frontend/app_flowy/packages/flowy_editor/lib/src/document/text_delta.dart+++ b/frontend/app_flowy/packages/flowy_editor/lib/src/document/text_delta.dart@@ -260,6 +260,7 @@ TextOperation? _textOperationFromJson(Map<String, dynamic> json) {class Delta extends Iterable<TextOperation> {final List<TextOperation> _operations;String? _rawString;+ List<int>? _runeIndexes;factory Delta.fromJson(List<dynamic> list) {final operations = <TextOperation>[];@@ -477,9 +478,23 @@ class Delta extends Iterable<TextOperation> {String toRawString() {_rawString ??=_operations.whereType<TextInsert>().map((op) => op.content).join();+ _runeIndexes ??= stringIndexes(_rawString!);return _rawString!;}@overrideIterator<TextOperation> get iterator => _operations.iterator;}++List<int> stringIndexes(String content) {+ final indexes = List<int>.filled(content.length, 0);+ final iterator = content.runes.iterator;++ while (iterator.moveNext()) {+ for (var i = 0; i < iterator.currentSize; i++) {+ indexes[iterator.rawIndex + i] = iterator.rawIndex;+ }+ }++ return indexes;+}diff --git a/frontend/app_flowy/packages/flowy_editor/test/delta_test.dart b/frontend/app_flowy/packages/flowy_editor/test/delta_test.dartindex 7016da70e4..2b0d529414 100644--- a/frontend/app_flowy/packages/flowy_editor/test/delta_test.dart+++ b/frontend/app_flowy/packages/flowy_editor/test/delta_test.dart@@ -279,4 +279,9 @@ void main() {expect(delta, expected);});});+ test("stringIndexes", () {+ final indexes = stringIndexes('😊');+ expect(indexes[0], 0);+ expect(indexes[1], 0);+ });}