diff --git a/example/assets/example.json b/example/assets/example.json index d5419d40b..dac41c33f 100644 --- a/example/assets/example.json +++ b/example/assets/example.json @@ -10,7 +10,7 @@ }, { "insert": "Welcome to", - "data": { + "attributes": { "bold": true } }, @@ -19,7 +19,7 @@ }, { "insert": "AppFlowy Editor", - "data": { + "attributes": { "href": "appflowy.io", "italic": true, "bold": true @@ -45,7 +45,7 @@ }, { "insert": "highly customizable", - "data": { + "attributes": { "bold": true } }, @@ -54,7 +54,7 @@ }, { "insert": "rich-text editor", - "data": { + "attributes": { "italic": true } }, @@ -63,7 +63,7 @@ }, { "insert": "Flutter", - "data": { + "attributes": { "underline": true } } @@ -125,7 +125,7 @@ }, { "insert": "AppFlowy Editor", - "data": { + "attributes": { "italic": true, "bold": true, "textColor": "0xffD70040", @@ -151,7 +151,6 @@ "insert": "Use / to insert blocks" }] } - }, { "type": "bulleted_list", diff --git a/example/lib/pages/simple_editor.dart b/example/lib/pages/simple_editor.dart index b40bcb966..b6cd72c3a 100644 --- a/example/lib/pages/simple_editor.dart +++ b/example/lib/pages/simple_editor.dart @@ -106,39 +106,8 @@ class SimpleEditor extends StatelessWidget { EditorState editorState, ScrollController? scrollController, ) { - final editorStyle = EditorStyle.desktop( - // Example for customizing a new attribute key. - textSpanDecorator: (textInsert, textSpan) { - final attributes = textInsert.attributes; - if (attributes == null) { - return textSpan; - } - final mention = attributes['mention'] as Map?; - if (mention != null) { - return WidgetSpan( - child: MouseRegion( - cursor: SystemMouseCursors.click, - child: GestureDetector( - behavior: HitTestBehavior.translucent, - onTap: () { - debugPrint('at'); - }, - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - const Icon(Icons.edit_document), - Text(mention['id']), - ], - ), - ), - ), - ); - } - return textSpan; - }, - ); return AppFlowyEditor.standard( - editorStyle: editorStyle, + editorStyle: const EditorStyle.desktop(), editorState: editorState, scrollController: scrollController, ); diff --git a/lib/src/core/transform/transaction.dart b/lib/src/core/transform/transaction.dart index 044787935..21389a0ef 100644 --- a/lib/src/core/transform/transaction.dart +++ b/lib/src/core/transform/transaction.dart @@ -677,7 +677,13 @@ extension on Delta { if (index <= 0) { return null; } - - return slice(index - 1, index).first.attributes; + final attributes = slice(index - 1, index).first.attributes; + if (attributes == null || + !attributes.keys.every( + (element) => FlowyRichTextKeys.supportSliced.contains(element), + )) { + return null; + } + return attributes; } } diff --git a/lib/src/render/rich_text/flowy_rich_text_keys.dart b/lib/src/render/rich_text/flowy_rich_text_keys.dart index fd3787935..18e9b8100 100644 --- a/lib/src/render/rich_text/flowy_rich_text_keys.dart +++ b/lib/src/render/rich_text/flowy_rich_text_keys.dart @@ -7,4 +7,13 @@ class FlowyRichTextKeys { static String highlightColor = 'bg_color'; static String code = 'code'; static String href = 'href'; + + static List supportSliced = [ + bold, + italic, + underline, + strikethrough, + textColor, + highlightColor, + ]; }