diff --git a/example/lib/pages/customize_theme_for_editor.dart b/example/lib/pages/customize_theme_for_editor.dart index dacc06b0e..224365762 100644 --- a/example/lib/pages/customize_theme_for_editor.dart +++ b/example/lib/pages/customize_theme_for_editor.dart @@ -181,20 +181,20 @@ class _CustomizeThemeForEditorState extends State { backgroundColor: Colors.black12, ), ), - textSpanDecorator: (context, node, index, text, textSpan) { + textSpanDecorator: (context, node, index, text, before, _) { final attributes = text.attributes; final href = attributes?[AppFlowyRichTextKeys.href]; if (href != null) { return TextSpan( text: text.text, - style: textSpan.style, + style: before.style, recognizer: TapGestureRecognizer() ..onTap = () { debugPrint('onTap: $href'); }, ); } - return textSpan; + return before; }, ); } diff --git a/lib/src/editor/block_component/rich_text/appflowy_rich_text.dart b/lib/src/editor/block_component/rich_text/appflowy_rich_text.dart index e943e91de..b023df8f9 100644 --- a/lib/src/editor/block_component/rich_text/appflowy_rich_text.dart +++ b/lib/src/editor/block_component/rich_text/appflowy_rich_text.dart @@ -21,7 +21,8 @@ typedef TextSpanDecoratorForAttribute = InlineSpan Function( Node node, int index, TextInsert text, - TextSpan textSpan, + TextSpan before, + TextSpan after, ); typedef AppFlowyTextSpanDecorator = TextSpan Function(TextSpan textSpan); @@ -380,6 +381,7 @@ class _AppFlowyRichTextState extends State offset, textInsert, textSpan, + widget.textSpanDecorator?.call(textSpan) ?? textSpan, ) : textSpan, ); diff --git a/lib/src/editor/editor_component/style/default_text_span_decorator_for_attribute.dart b/lib/src/editor/editor_component/style/default_text_span_decorator_for_attribute.dart index 9b9393ae3..172ce8050 100644 --- a/lib/src/editor/editor_component/style/default_text_span_decorator_for_attribute.dart +++ b/lib/src/editor/editor_component/style/default_text_span_decorator_for_attribute.dart @@ -2,7 +2,6 @@ import 'dart:async'; import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/gestures.dart'; - import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -13,11 +12,12 @@ TextSpan defaultTextSpanDecoratorForAttribute( Node node, int index, TextInsert text, - TextSpan textSpan, + TextSpan before, + TextSpan after, ) { final attributes = text.attributes; if (attributes == null) { - return textSpan; + return before; } final editorState = context.read(); final href = attributes[AppFlowyRichTextKeys.href] as String?; @@ -52,10 +52,10 @@ TextSpan defaultTextSpanDecoratorForAttribute( }); }; return TextSpan( - style: textSpan.style, + style: before.style, text: text.text, recognizer: tapGestureRecognizer, ); } - return textSpan; + return before; } diff --git a/lib/src/editor/editor_component/style/mobile_text_span_decorator_for_attribute.dart b/lib/src/editor/editor_component/style/mobile_text_span_decorator_for_attribute.dart index 43188d331..804f1d4dc 100644 --- a/lib/src/editor/editor_component/style/mobile_text_span_decorator_for_attribute.dart +++ b/lib/src/editor/editor_component/style/mobile_text_span_decorator_for_attribute.dart @@ -12,11 +12,12 @@ TextSpan mobileTextSpanDecoratorForAttribute( Node node, int index, TextInsert text, - TextSpan textSpan, + TextSpan before, + TextSpan after, ) { final attributes = text.attributes; if (attributes == null) { - return textSpan; + return before; } final editorState = context.read(); @@ -69,13 +70,13 @@ TextSpan mobileTextSpanDecoratorForAttribute( }); }; return TextSpan( - style: textSpan.style, + style: before.style, text: text.text, recognizer: tapGestureRecognizer, ); } - return textSpan; + return before; } class LinkEditForm extends StatefulWidget { diff --git a/test/customer/custom_attribute_for_text_block_test.dart b/test/customer/custom_attribute_for_text_block_test.dart index 4adfe8893..8d4c672b7 100644 --- a/test/customer/custom_attribute_for_text_block_test.dart +++ b/test/customer/custom_attribute_for_text_block_test.dart @@ -32,7 +32,7 @@ class CustomAttributeKeyForTextBlock extends StatelessWidget { Widget build(BuildContext context) { final editorStyle = EditorStyle.desktop( // Example for customizing a new attribute key. - textSpanDecorator: (_, __, ___, textInsert, textSpan) { + textSpanDecorator: (_, __, ___, textInsert, textSpan, ____) { final attributes = textInsert.attributes; if (attributes == null) { return textSpan;