Skip to content

Commit

Permalink
feat: public node and index in TextSpanDecoratorForCustomAttributes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 authored Jul 5, 2023
1 parent bb3771a commit 2ed30f3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/src/editor/editor_component/style/editor_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class EditorStyle extends ThemeExtension<EditorStyle> {
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),
Expand Down
13 changes: 10 additions & 3 deletions lib/src/render/rich_text/flowy_rich_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down Expand Up @@ -291,17 +293,22 @@ class _FlowyRichTextState extends State<FlowyRichText> with SelectableMixin {
);
}
}
offset += textInsert.length;
final textSpan = TextSpan(
text: textInsert.text,
style: textStyle,
recognizer: recognizer,
);
textSpans.add(
textSpanDecoratorForCustomAttributes != null
? textSpanDecoratorForCustomAttributes!(textInsert, textSpan)
? textSpanDecoratorForCustomAttributes!(
widget.node,
offset,
textInsert,
textSpan,
)
: textSpan,
);
offset += textInsert.length;
}
return TextSpan(
children: textSpans,
Expand Down
2 changes: 1 addition & 1 deletion test/customer/custom_attribute_for_text_block_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2ed30f3

Please sign in to comment.