Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: extend attribute keys shouldn't be sliced #248

Merged
merged 1 commit into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions example/assets/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
{
"insert": "Welcome to",
"data": {
"attributes": {
"bold": true
}
},
Expand All @@ -19,7 +19,7 @@
},
{
"insert": "AppFlowy Editor",
"data": {
"attributes": {
"href": "appflowy.io",
"italic": true,
"bold": true
Expand All @@ -45,7 +45,7 @@
},
{
"insert": "highly customizable",
"data": {
"attributes": {
"bold": true
}
},
Expand All @@ -54,7 +54,7 @@
},
{
"insert": "rich-text editor",
"data": {
"attributes": {
"italic": true
}
},
Expand All @@ -63,7 +63,7 @@
},
{
"insert": "Flutter",
"data": {
"attributes": {
"underline": true
}
}
Expand Down Expand Up @@ -125,7 +125,7 @@
},
{
"insert": "AppFlowy Editor",
"data": {
"attributes": {
"italic": true,
"bold": true,
"textColor": "0xffD70040",
Expand All @@ -151,7 +151,6 @@
"insert": "Use / to insert blocks"
}]
}

},
{
"type": "bulleted_list",
Expand Down
33 changes: 1 addition & 32 deletions example/lib/pages/simple_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
10 changes: 8 additions & 2 deletions lib/src/core/transform/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
9 changes: 9 additions & 0 deletions lib/src/render/rich_text/flowy_rich_text_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@ class FlowyRichTextKeys {
static String highlightColor = 'bg_color';
static String code = 'code';
static String href = 'href';

static List<String> supportSliced = [
bold,
italic,
underline,
strikethrough,
textColor,
highlightColor,
];
}