From 2ed30f390389ec6a3f857149672c94274ec6be15 Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Wed, 5 Jul 2023 16:09:05 +0800 Subject: [PATCH] feat: public node and index in TextSpanDecoratorForCustomAttributes (#288) --- .../editor/editor_component/style/editor_style.dart | 2 +- lib/src/render/rich_text/flowy_rich_text.dart | 13 ++++++++++--- .../custom_attribute_for_text_block_test.dart | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/src/editor/editor_component/style/editor_style.dart b/lib/src/editor/editor_component/style/editor_style.dart index 52d1eff4d..336d60bd4 100644 --- a/lib/src/editor/editor_component/style/editor_style.dart +++ b/lib/src/editor/editor_component/style/editor_style.dart @@ -328,7 +328,7 @@ class EditorStyle extends ThemeExtension { textStyleConfiguration: const TextStyleConfiguration( text: TextStyle(fontSize: 16, color: Colors.black), ), - textSpanDecorator: (_, textSpan) => textSpan, + textSpanDecorator: (_, __, ___, textSpan) => textSpan, selectionColor: const Color.fromARGB(53, 111, 201, 231), selectionMenuBackgroundColor: const Color(0xFFFFFFFF), selectionMenuItemTextColor: const Color(0xFF333333), diff --git a/lib/src/render/rich_text/flowy_rich_text.dart b/lib/src/render/rich_text/flowy_rich_text.dart index 895bfb168..6fe016aa0 100644 --- a/lib/src/render/rich_text/flowy_rich_text.dart +++ b/lib/src/render/rich_text/flowy_rich_text.dart @@ -19,7 +19,9 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; typedef TextSpanDecoratorForCustomAttributes = InlineSpan Function( - TextInsert attributeKey, + Node node, + int index, + TextInsert text, TextSpan textSpan, ); @@ -291,7 +293,6 @@ class _FlowyRichTextState extends State with SelectableMixin { ); } } - offset += textInsert.length; final textSpan = TextSpan( text: textInsert.text, style: textStyle, @@ -299,9 +300,15 @@ class _FlowyRichTextState extends State with SelectableMixin { ); textSpans.add( textSpanDecoratorForCustomAttributes != null - ? textSpanDecoratorForCustomAttributes!(textInsert, textSpan) + ? textSpanDecoratorForCustomAttributes!( + widget.node, + offset, + textInsert, + textSpan, + ) : textSpan, ); + offset += textInsert.length; } return TextSpan( children: textSpans, diff --git a/test/customer/custom_attribute_for_text_block_test.dart b/test/customer/custom_attribute_for_text_block_test.dart index 462b03563..198630158 100644 --- a/test/customer/custom_attribute_for_text_block_test.dart +++ b/test/customer/custom_attribute_for_text_block_test.dart @@ -29,7 +29,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;