Skip to content

Commit

Permalink
feat: support get the after text decorate from textSpanDecorator (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 authored Dec 4, 2023
1 parent 9c7a4ee commit 4995d21
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions example/lib/pages/customize_theme_for_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,20 @@ class _CustomizeThemeForEditorState extends State<CustomizeThemeForEditor> {
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;
},
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -380,6 +381,7 @@ class _AppFlowyRichTextState extends State<AppFlowyRichText>
offset,
textInsert,
textSpan,
widget.textSpanDecorator?.call(textSpan) ?? textSpan,
)
: textSpan,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<EditorState>();
final href = attributes[AppFlowyRichTextKeys.href] as String?;
Expand Down Expand Up @@ -52,10 +52,10 @@ TextSpan defaultTextSpanDecoratorForAttribute(
});
};
return TextSpan(
style: textSpan.style,
style: before.style,
text: text.text,
recognizer: tapGestureRecognizer,
);
}
return textSpan;
return before;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<EditorState>();

Expand Down Expand Up @@ -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 {
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 @@ -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;
Expand Down

0 comments on commit 4995d21

Please sign in to comment.