Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

relicense appflowy editor (#1938)

Lucas.Xu5e8f6a53a015
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/board/board_menu_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/board/board_menu_item.dart
index a368951f30..cccb671e7c 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/board/board_menu_item.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/board/board_menu_item.dart
@@ -7,7 +7,7 @@ import 'package:flowy_infra/image.dart';
import 'package:flutter/material.dart';
SelectionMenuItem boardMenuItem = SelectionMenuItem(
- name: () => LocaleKeys.document_plugins_referencedBoard.tr(),
+ name: LocaleKeys.document_plugins_referencedBoard.tr(),
icon: (editorState, onSelected) {
return svgWidget(
'editor/board',
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/grid/grid_menu_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/grid/grid_menu_item.dart
index e69b406c7c..737c17f4f5 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/grid/grid_menu_item.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/grid/grid_menu_item.dart
@@ -7,7 +7,7 @@ import 'package:flowy_infra/image.dart';
import 'package:flutter/material.dart';
SelectionMenuItem gridMenuItem = SelectionMenuItem(
- name: () => LocaleKeys.document_plugins_referencedGrid.tr(),
+ name: LocaleKeys.document_plugins_referencedGrid.tr(),
icon: (editorState, onSelected) {
return svgWidget(
'editor/grid',
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/horizontal_rule_node_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/horizontal_rule_node_widget.dart
index c3d4cbeb35..7053e6f2ac 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/horizontal_rule_node_widget.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/plugins/horizontal_rule_node_widget.dart
@@ -37,7 +37,7 @@ ShortcutEventHandler _insertHorzaontalRule = (editorState, event) {
};
SelectionMenuItem horizontalRuleMenuItem = SelectionMenuItem(
- name: () => 'Horizontal rule',
+ name: 'Horizontal rule',
icon: (editorState, onSelected) => Icon(
Icons.horizontal_rule,
color: onSelected
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor/example/lib/plugin/AI/auto_completion.dart b/frontend/appflowy_flutter/packages/appflowy_editor/example/lib/plugin/AI/auto_completion.dart
index c2e9447b6b..e90f8bd3d2 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor/example/lib/plugin/AI/auto_completion.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor/example/lib/plugin/AI/auto_completion.dart
@@ -5,7 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
SelectionMenuItem autoCompletionMenuItem = SelectionMenuItem(
- name: () => 'Auto generate content',
+ name: 'Auto generate content',
icon: (editorState, onSelected) => Icon(
Icons.rocket,
size: 18.0,
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor/example/lib/plugin/AI/continue_to_write.dart b/frontend/appflowy_flutter/packages/appflowy_editor/example/lib/plugin/AI/continue_to_write.dart
index e3e407d481..4e0b2ec100 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor/example/lib/plugin/AI/continue_to_write.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor/example/lib/plugin/AI/continue_to_write.dart
@@ -4,7 +4,7 @@ import 'package:example/plugin/AI/text_robot.dart';
import 'package:flutter/material.dart';
SelectionMenuItem continueToWriteMenuItem = SelectionMenuItem(
- name: () => 'Continue To Write',
+ name: 'Continue To Write',
icon: (editorState, onSelected) => Icon(
Icons.print,
size: 18.0,
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/core/legacy/built_in_attribute_keys.dart b/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/core/legacy/built_in_attribute_keys.dart
index 3f334bdd0a..6421e7efd0 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/core/legacy/built_in_attribute_keys.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/core/legacy/built_in_attribute_keys.dart
@@ -37,7 +37,6 @@ class BuiltInAttributeKey {
static String checkbox = 'checkbox';
static String code = 'code';
static String number = 'number';
- static String defaultFormating = 'defaultFormating';
static List<String> partialStyleKeys = [
BuiltInAttributeKey.bold,
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/render/selection_menu/selection_menu_item_widget.dart b/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/render/selection_menu/selection_menu_item_widget.dart
index 912d9447ff..1d3a73f93e 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/render/selection_menu/selection_menu_item_widget.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/render/selection_menu/selection_menu_item_widget.dart
@@ -47,7 +47,7 @@ class _SelectionMenuItemWidgetState extends State<SelectionMenuItemWidget> {
: MaterialStateProperty.all(Colors.transparent),
),
label: Text(
- widget.item.name(),
+ widget.item.name,
textAlign: TextAlign.left,
style: TextStyle(
color: (widget.isSelected || _onHover)
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/render/selection_menu/selection_menu_service.dart b/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/render/selection_menu/selection_menu_service.dart
index 498438e6be..7e0ce3eeea 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/render/selection_menu/selection_menu_service.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/render/selection_menu/selection_menu_service.dart
@@ -156,7 +156,7 @@ List<SelectionMenuItem> get defaultSelectionMenuItems =>
_defaultSelectionMenuItems;
final List<SelectionMenuItem> _defaultSelectionMenuItems = [
SelectionMenuItem(
- name: () => AppFlowyEditorLocalizations.current.text,
+ name: AppFlowyEditorLocalizations.current.text,
icon: (editorState, onSelected) =>
_selectionMenuIcon('text', editorState, onSelected),
keywords: ['text'],
@@ -165,7 +165,7 @@ final List<SelectionMenuItem> _defaultSelectionMenuItems = [
},
),
SelectionMenuItem(
- name: () => AppFlowyEditorLocalizations.current.heading1,
+ name: AppFlowyEditorLocalizations.current.heading1,
icon: (editorState, onSelected) =>
_selectionMenuIcon('h1', editorState, onSelected),
keywords: ['heading 1, h1'],
@@ -174,7 +174,7 @@ final List<SelectionMenuItem> _defaultSelectionMenuItems = [
},
),
SelectionMenuItem(
- name: () => AppFlowyEditorLocalizations.current.heading2,
+ name: AppFlowyEditorLocalizations.current.heading2,
icon: (editorState, onSelected) =>
_selectionMenuIcon('h2', editorState, onSelected),
keywords: ['heading 2, h2'],
@@ -183,7 +183,7 @@ final List<SelectionMenuItem> _defaultSelectionMenuItems = [
},
),
SelectionMenuItem(
- name: () => AppFlowyEditorLocalizations.current.heading3,
+ name: AppFlowyEditorLocalizations.current.heading3,
icon: (editorState, onSelected) =>
_selectionMenuIcon('h3', editorState, onSelected),
keywords: ['heading 3, h3'],
@@ -192,14 +192,14 @@ final List<SelectionMenuItem> _defaultSelectionMenuItems = [
},
),
SelectionMenuItem(
- name: () => AppFlowyEditorLocalizations.current.image,
+ name: AppFlowyEditorLocalizations.current.image,
icon: (editorState, onSelected) =>
_selectionMenuIcon('image', editorState, onSelected),
keywords: ['image'],
handler: showImageUploadMenu,
),
SelectionMenuItem(
- name: () => AppFlowyEditorLocalizations.current.bulletedList,
+ name: AppFlowyEditorLocalizations.current.bulletedList,
icon: (editorState, onSelected) =>
_selectionMenuIcon('bulleted_list', editorState, onSelected),
keywords: ['bulleted list', 'list', 'unordered list'],
@@ -208,7 +208,7 @@ final List<SelectionMenuItem> _defaultSelectionMenuItems = [
},
),
SelectionMenuItem(
- name: () => AppFlowyEditorLocalizations.current.numberedList,
+ name: AppFlowyEditorLocalizations.current.numberedList,
icon: (editorState, onSelected) =>
_selectionMenuIcon('number', editorState, onSelected),
keywords: ['numbered list', 'list', 'ordered list'],
@@ -217,7 +217,7 @@ final List<SelectionMenuItem> _defaultSelectionMenuItems = [
},
),
SelectionMenuItem(
- name: () => AppFlowyEditorLocalizations.current.checkbox,
+ name: AppFlowyEditorLocalizations.current.checkbox,
icon: (editorState, onSelected) =>
_selectionMenuIcon('checkbox', editorState, onSelected),
keywords: ['todo list', 'list', 'checkbox list'],
@@ -226,7 +226,7 @@ final List<SelectionMenuItem> _defaultSelectionMenuItems = [
},
),
SelectionMenuItem(
- name: () => AppFlowyEditorLocalizations.current.quote,
+ name: AppFlowyEditorLocalizations.current.quote,
icon: (editorState, onSelected) =>
_selectionMenuIcon('quote', editorState, onSelected),
keywords: ['quote', 'refer'],
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/render/selection_menu/selection_menu_widget.dart b/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/render/selection_menu/selection_menu_widget.dart
index 0d96853d74..3a88cfcd4a 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/render/selection_menu/selection_menu_widget.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/render/selection_menu/selection_menu_widget.dart
@@ -20,14 +20,14 @@ class SelectionMenuItem {
required SelectionMenuItemHandler handler,
}) {
this.handler = (editorState, menuService, context) {
- _deleteToSlash(editorState);
+ _deleteSlash(editorState);
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
handler(editorState, menuService, context);
});
};
}
- final String Function() name;
+ final String name;
final Widget Function(EditorState editorState, bool onSelected) icon;
/// Customizes keywords for item.
@@ -36,20 +36,23 @@ class SelectionMenuItem {
final List<String> keywords;
late final SelectionMenuItemHandler handler;
- void _deleteToSlash(EditorState editorState) {
+ void _deleteSlash(EditorState editorState) {
final selectionService = editorState.service.selectionService;
final selection = selectionService.currentSelection.value;
final nodes = selectionService.currentSelectedNodes;
if (selection != null && nodes.length == 1) {
final node = nodes.first as TextNode;
final end = selection.start.offset;
- final start = node.toPlainText().substring(0, end).lastIndexOf('/');
+ final lastSlashIndex =
+ node.toPlainText().substring(0, end).lastIndexOf('/');
+ // delete all the texts after '/' along with '/'
final transaction = editorState.transaction
..deleteText(
node,
- start,
- selection.start.offset - start,
+ lastSlashIndex,
+ end - lastSlashIndex,
);
+
editorState.apply(transaction);
}
}
@@ -81,7 +84,7 @@ class SelectionMenuItem {
updateSelection,
}) {
return SelectionMenuItem(
- name: () => name,
+ name: name,
icon: (editorState, onSelected) => Icon(
iconData,
color: onSelected
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/markdown_syntax_to_styled_text.dart b/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/markdown_syntax_to_styled_text.dart
index 94caff83b1..b38d838fed 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/markdown_syntax_to_styled_text.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/markdown_syntax_to_styled_text.dart
@@ -265,8 +265,9 @@ ShortcutEventHandler markdownLinkOrImageHandler = (editorState, event) {
return KeyEventResult.handled;
};
-// convert **abc** to bold abc.
-ShortcutEventHandler doubleAsterisksToBold = (editorState, event) {
+ShortcutEventHandler underscoreToItalicHandler = (editorState, event) {
+ // Obtain the selection and selected nodes of the current document through the 'selectionService'
+ // to determine whether the selection is collapsed and whether the selected node is a text node.
final selectionService = editorState.service.selectionService;
final selection = selectionService.currentSelection.value;
final textNodes = selectionService.currentSelectedNodes.whereType<TextNode>();
@@ -275,53 +276,33 @@ ShortcutEventHandler doubleAsterisksToBold = (editorState, event) {
}
final textNode = textNodes.first;
- final text = textNode.toPlainText().substring(0, selection.end.offset);
-
- // make sure the last two characters are **.
- if (text.length < 2 || text[selection.end.offset - 1] != '*') {
- return KeyEventResult.ignored;
- }
-
- // find all the index of `*`.
- final asteriskIndexes = <int>[];
- for (var i = 0; i < text.length; i++) {
- if (text[i] == '*') {
- asteriskIndexes.add(i);
- }
- }
-
- if (asteriskIndexes.length < 3) {
- return KeyEventResult.ignored;
- }
-
- // make sure the second to last and third to last asterisks are connected.
- final thirdToLastAsteriskIndex = asteriskIndexes[asteriskIndexes.length - 3];
- final secondToLastAsteriskIndex = asteriskIndexes[asteriskIndexes.length - 2];
- final lastAsterisIndex = asteriskIndexes[asteriskIndexes.length - 1];
- if (secondToLastAsteriskIndex != thirdToLastAsteriskIndex + 1 ||
- lastAsterisIndex == secondToLastAsteriskIndex + 1) {
+ final text = textNode.toPlainText();
+ // Determine if an 'underscore' already exists in the text node and only once.
+ final firstUnderscore = text.indexOf('_');
+ final lastUnderscore = text.lastIndexOf('_');
+ if (firstUnderscore == -1 ||
+ firstUnderscore != lastUnderscore ||
+ firstUnderscore == selection.start.offset - 1) {
return KeyEventResult.ignored;
}
- // delete the last three asterisks.
- // update the style of the text surround by `** **` to bold.
+ // Delete the previous 'underscore',
+ // update the style of the text surrounded by the two underscores to 'italic',
// and update the cursor position.
final transaction = editorState.transaction
- ..deleteText(textNode, lastAsterisIndex, 1)
- ..deleteText(textNode, thirdToLastAsteriskIndex, 2)
+ ..deleteText(textNode, firstUnderscore, 1)
..formatText(
textNode,
- thirdToLastAsteriskIndex,
- selection.end.offset - thirdToLastAsteriskIndex - 3,
+ firstUnderscore,
+ selection.end.offset - firstUnderscore - 1,
{
- BuiltInAttributeKey.bold: true,
- BuiltInAttributeKey.defaultFormating: true,
+ BuiltInAttributeKey.italic: true,
},
)
..afterSelection = Selection.collapsed(
Position(
path: textNode.path,
- offset: selection.end.offset - 3,
+ offset: selection.end.offset - 1,
),
);
editorState.apply(transaction);
@@ -329,111 +310,115 @@ ShortcutEventHandler doubleAsterisksToBold = (editorState, event) {
return KeyEventResult.handled;
};
-// convert __abc__ to bold abc.
-ShortcutEventHandler doubleUnderscoresToBold = (editorState, event) {
+ShortcutEventHandler doubleAsteriskToBoldHanlder = (editorState, event) {
final selectionService = editorState.service.selectionService;
final selection = selectionService.currentSelection.value;
final textNodes = selectionService.currentSelectedNodes.whereType<TextNode>();
+
if (selection == null || !selection.isSingle || textNodes.length != 1) {
return KeyEventResult.ignored;
}
final textNode = textNodes.first;
- final text = textNode.toPlainText().substring(0, selection.end.offset);
+ final text = textNode.toPlainText();
- // make sure the last two characters are __.
- if (text.length < 2 || text[selection.end.offset - 1] != '_') {
+// make sure the last two characters are '**'
+ if (text.length < 2 || text[selection.end.offset - 1] != '*') {
return KeyEventResult.ignored;
}
- // find all the index of `_`.
- final underscoreIndexes = <int>[];
+// find all the index of '*'
+ final asteriskIndexList = <int>[];
for (var i = 0; i < text.length; i++) {
- if (text[i] == '_') {
- underscoreIndexes.add(i);
+ if (text[i] == '*') {
+ asteriskIndexList.add(i);
}
}
- if (underscoreIndexes.length < 3) {
- return KeyEventResult.ignored;
- }
+ if (asteriskIndexList.length < 3) return KeyEventResult.ignored;
- // make sure the second to last and third to last underscores are connected.
- final thirdToLastUnderscoreIndex =
- underscoreIndexes[underscoreIndexes.length - 3];
- final secondToLastUnderscoreIndex =
- underscoreIndexes[underscoreIndexes.length - 2];
- final lastAsterisIndex = underscoreIndexes[underscoreIndexes.length - 1];
- if (secondToLastUnderscoreIndex != thirdToLastUnderscoreIndex + 1 ||
- lastAsterisIndex == secondToLastUnderscoreIndex + 1) {
+// make sure the second to last and third to last asterisk are connected
+ final thirdToLastAsteriskIndex =
+ asteriskIndexList[asteriskIndexList.length - 3];
+ final secondToLastAsteriskIndex =
+ asteriskIndexList[asteriskIndexList.length - 2];
+ final lastAsteriskIndex = asteriskIndexList[asteriskIndexList.length - 1];
+ if (secondToLastAsteriskIndex != thirdToLastAsteriskIndex + 1 ||
+ lastAsteriskIndex == secondToLastAsteriskIndex + 1) {
return KeyEventResult.ignored;
}
- // delete the last three underscores.
- // update the style of the text surround by `__ __` to bold.
- // and update the cursor position.
+//delete the last three asterisks
+//update the style of the text surround by '** **' to bold
+//update the cursor position
final transaction = editorState.transaction
- ..deleteText(textNode, lastAsterisIndex, 1)
- ..deleteText(textNode, thirdToLastUnderscoreIndex, 2)
- ..formatText(
- textNode,
- thirdToLastUnderscoreIndex,
- selection.end.offset - thirdToLastUnderscoreIndex - 3,
- {
- BuiltInAttributeKey.bold: true,
- BuiltInAttributeKey.defaultFormating: true,
- },
- )
+ ..deleteText(textNode, lastAsteriskIndex, 1)
+ ..deleteText(textNode, thirdToLastAsteriskIndex, 2)
+ ..formatText(textNode, thirdToLastAsteriskIndex,
+ selection.end.offset - thirdToLastAsteriskIndex - 2, {
+ BuiltInAttributeKey.bold: true,
+ })
..afterSelection = Selection.collapsed(
- Position(
- path: textNode.path,
- offset: selection.end.offset - 3,
- ),
- );
+ Position(path: textNode.path, offset: selection.end.offset - 3));
+
editorState.apply(transaction);
+
return KeyEventResult.handled;
};
-ShortcutEventHandler underscoreToItalicHandler = (editorState, event) {
- // Obtain the selection and selected nodes of the current document through the 'selectionService'
- // to determine whether the selection is collapsed and whether the selected node is a text node.
+//Implement in the same way as doubleAsteriskToBoldHanlder
+ShortcutEventHandler doubleUnderscoreToBoldHanlder = (editorState, event) {
final selectionService = editorState.service.selectionService;
final selection = selectionService.currentSelection.value;
final textNodes = selectionService.currentSelectedNodes.whereType<TextNode>();
+
if (selection == null || !selection.isSingle || textNodes.length != 1) {
return KeyEventResult.ignored;
}
final textNode = textNodes.first;
final text = textNode.toPlainText();
- // Determine if an 'underscore' already exists in the text node and only once.
- final firstUnderscore = text.indexOf('_');
- final lastUnderscore = text.lastIndexOf('_');
- if (firstUnderscore == -1 ||
- firstUnderscore != lastUnderscore ||
- firstUnderscore == selection.start.offset - 1) {
+
+// make sure the last two characters are '__'
+ if (text.length < 2 || text[selection.end.offset - 1] != '_') {
return KeyEventResult.ignored;
}
- // Delete the previous 'underscore',
- // update the style of the text surrounded by the two underscores to 'italic',
- // and update the cursor position.
+// find all the index of '_'
+ final underscoreIndexList = <int>[];
+ for (var i = 0; i < text.length; i++) {
+ if (text[i] == '_') {
+ underscoreIndexList.add(i);
+ }
+ }
+
+ if (underscoreIndexList.length < 3) return KeyEventResult.ignored;
+
+// make sure the second to last and third to last underscore are connected
+ final thirdToLastUnderscoreIndex =
+ underscoreIndexList[underscoreIndexList.length - 3];
+ final secondToLastUnderscoreIndex =
+ underscoreIndexList[underscoreIndexList.length - 2];
+ final lastUnderscoreIndex =
+ underscoreIndexList[underscoreIndexList.length - 1];
+ if (secondToLastUnderscoreIndex != thirdToLastUnderscoreIndex + 1 ||
+ lastUnderscoreIndex == secondToLastUnderscoreIndex + 1) {
+ return KeyEventResult.ignored;
+ }
+
+//delete the last three underscores
+//update the style of the text surround by '__ __' to bold
+//update the cursor position
final transaction = editorState.transaction
- ..deleteText(textNode, firstUnderscore, 1)
- ..formatText(
- textNode,
- firstUnderscore,
- selection.end.offset - firstUnderscore - 1,
- {
- BuiltInAttributeKey.italic: true,
- },
- )
+ ..deleteText(textNode, lastUnderscoreIndex, 1)
+ ..deleteText(textNode, thirdToLastUnderscoreIndex, 2)
+ ..formatText(textNode, thirdToLastUnderscoreIndex,
+ selection.end.offset - thirdToLastUnderscoreIndex - 2, {
+ BuiltInAttributeKey.bold: true,
+ })
..afterSelection = Selection.collapsed(
- Position(
- path: textNode.path,
- offset: selection.end.offset - 1,
- ),
- );
+ Position(path: textNode.path, offset: selection.end.offset - 3));
+
editorState.apply(transaction);
return KeyEventResult.handled;
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/service/shortcut_event/built_in_shortcut_events.dart b/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/service/shortcut_event/built_in_shortcut_events.dart
index 6c1c7bc259..d6338b6fe3 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/service/shortcut_event/built_in_shortcut_events.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor/lib/src/service/shortcut_event/built_in_shortcut_events.dart
@@ -1,5 +1,3 @@
-// List<>
-
import 'package:appflowy_editor/src/service/internal_key_event_handlers/arrow_keys_handler.dart';
import 'package:appflowy_editor/src/service/internal_key_event_handlers/backspace_handler.dart';
import 'package:appflowy_editor/src/service/internal_key_event_handlers/copy_paste_handler.dart';
@@ -284,16 +282,6 @@ List<ShortcutEvent> builtInShortcutEvents = [
command: 'tab',
handler: tabHandler,
),
- ShortcutEvent(
- key: 'Double stars to bold',
- command: 'shift+asterisk',
- handler: doubleAsterisksToBold,
- ),
- ShortcutEvent(
- key: 'Double underscores to bold',
- command: 'shift+underscore',
- handler: doubleUnderscoresToBold,
- ),
ShortcutEvent(
key: 'Backquote to code',
command: 'backquote',
@@ -319,6 +307,16 @@ List<ShortcutEvent> builtInShortcutEvents = [
command: 'shift+underscore',
handler: underscoreToItalicHandler,
),
+ ShortcutEvent(
+ key: 'Double asterisk to bold',
+ command: 'shift+digit 8',
+ handler: doubleAsteriskToBoldHanlder,
+ ),
+ ShortcutEvent(
+ key: 'Double underscore to bold',
+ command: 'shift+underscore',
+ handler: doubleUnderscoreToBoldHanlder,
+ ),
// https://github.com/flutter/flutter/issues/104944
// Workaround: Using space editing on the web platform often results in errors,
// so adding a shortcut event to handle the space input instead of using the
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor/test/infra/test_raw_key_event.dart b/frontend/appflowy_flutter/packages/appflowy_editor/test/infra/test_raw_key_event.dart
index d00e458e5c..0a3d6cd74f 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor/test/infra/test_raw_key_event.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor/test/infra/test_raw_key_event.dart
@@ -142,15 +142,15 @@ extension on LogicalKeyboardKey {
if (this == LogicalKeyboardKey.keyZ) {
return PhysicalKeyboardKey.keyZ;
}
- if (this == LogicalKeyboardKey.asterisk) {
+ if (this == LogicalKeyboardKey.tilde) {
+ return PhysicalKeyboardKey.backquote;
+ }
+ if (this == LogicalKeyboardKey.digit8) {
return PhysicalKeyboardKey.digit8;
}
if (this == LogicalKeyboardKey.underscore) {
return PhysicalKeyboardKey.minus;
}
- if (this == LogicalKeyboardKey.tilde) {
- return PhysicalKeyboardKey.backquote;
- }
throw UnimplementedError();
}
}
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor/test/render/rich_text/checkbox_text_test.dart b/frontend/appflowy_flutter/packages/appflowy_editor/test/render/rich_text/checkbox_text_test.dart
index e396dbbf03..eceb429894 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor/test/render/rich_text/checkbox_text_test.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor/test/render/rich_text/checkbox_text_test.dart
@@ -70,7 +70,7 @@ void main() async {
});
// https://github.com/AppFlowy-IO/AppFlowy/issues/1763
- // [Bug] Mouse unable to click a certain area #1763
+ // // [Bug] Mouse unable to click a certain area #1763
testWidgets('insert a new checkbox after an exsiting checkbox',
(tester) async {
// Before
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor/test/render/selection_menu/selection_menu_widget_test.dart b/frontend/appflowy_flutter/packages/appflowy_editor/test/render/selection_menu/selection_menu_widget_test.dart
index 99a4674efd..6b392cdebb 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor/test/render/selection_menu/selection_menu_widget_test.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor/test/render/selection_menu/selection_menu_widget_test.dart
@@ -10,40 +10,44 @@ void main() async {
});
group('selection_menu_widget.dart', () {
- for (var i = 0; i < defaultSelectionMenuItems.length; i += 1) {
- testWidgets('Selects number.$i item in selection menu with enter',
- (tester) async {
- final editor = await _prepare(tester);
- for (var j = 0; j < i; j++) {
- await editor.pressLogicKey(LogicalKeyboardKey.arrowDown);
- }
-
- await editor.pressLogicKey(LogicalKeyboardKey.enter);
- expect(
- find.byType(SelectionMenuWidget, skipOffstage: false),
- findsNothing,
- );
- if (defaultSelectionMenuItems[i].name() != 'Image') {
- await _testDefaultSelectionMenuItems(i, editor);
- }
- });
-
- testWidgets('Selects number.$i item in selection menu with click',
- (tester) async {
- final editor = await _prepare(tester);
+ // const i = defaultSelectionMenuItems.length;
+ //
+ // Because the `defaultSelectionMenuItems` uses localization,
+ // and the MaterialApp has not been initialized at the time of getting the value,
+ // it will crash.
+ //
+ // Use const value temporarily instead.
+ const i = 7;
+ testWidgets('Selects number.$i item in selection menu with keyboard',
+ (tester) async {
+ final editor = await _prepare(tester);
+ for (var j = 0; j < i; j++) {
+ await editor.pressLogicKey(LogicalKeyboardKey.arrowDown);
+ }
- await tester.tap(find.byType(SelectionMenuItemWidget).at(i));
- await tester.pumpAndSettle();
+ await editor.pressLogicKey(LogicalKeyboardKey.enter);
+ expect(
+ find.byType(SelectionMenuWidget, skipOffstage: false),
+ findsNothing,
+ );
+ if (defaultSelectionMenuItems[i].name != 'Image') {
+ await _testDefaultSelectionMenuItems(i, editor);
+ }
+ });
- expect(
- find.byType(SelectionMenuWidget, skipOffstage: false),
- findsNothing,
- );
- if (defaultSelectionMenuItems[i].name() != 'Image') {
- await _testDefaultSelectionMenuItems(i, editor);
- }
- });
- }
+ testWidgets('Selects number.$i item in selection menu with clicking',
+ (tester) async {
+ final editor = await _prepare(tester);
+ await tester.tap(find.byType(SelectionMenuItemWidget).at(i));
+ await tester.pumpAndSettle();
+ expect(
+ find.byType(SelectionMenuWidget, skipOffstage: false),
+ findsNothing,
+ );
+ if (defaultSelectionMenuItems[i].name != 'Image') {
+ await _testDefaultSelectionMenuItems(i, editor);
+ }
+ });
testWidgets('Search item in selection menu util no results',
(tester) async {
@@ -136,7 +140,7 @@ Future<EditorWidgetTester> _prepare(WidgetTester tester) async {
);
for (final item in defaultSelectionMenuItems) {
- expect(find.text(item.name()), findsOneWidget);
+ expect(find.text(item.name), findsOneWidget);
}
return Future.value(editor);
@@ -146,28 +150,31 @@ Future<void> _testDefaultSelectionMenuItems(
int index, EditorWidgetTester editor) async {
expect(editor.documentLength, 4);
expect(editor.documentSelection, Selection.single(path: [2], startOffset: 0));
+ expect((editor.nodeAtPath([0]) as TextNode).toPlainText(),
+ 'Welcome to Appflowy 😁');
expect((editor.nodeAtPath([1]) as TextNode).toPlainText(),
'Welcome to Appflowy 😁');
final node = editor.nodeAtPath([2]);
final item = defaultSelectionMenuItems[index];
- final itemName = item.name();
- if (itemName == 'Text') {
+ if (item.name == 'Text') {
expect(node?.subtype == null, true);
- } else if (itemName == 'Heading 1') {
+ expect(node?.toString(), null);
+ } else if (item.name == 'Heading 1') {
expect(node?.subtype, BuiltInAttributeKey.heading);
expect(node?.attributes.heading, BuiltInAttributeKey.h1);
- } else if (itemName == 'Heading 2') {
+ expect(node?.toString(), null);
+ } else if (item.name == 'Heading 2') {
expect(node?.subtype, BuiltInAttributeKey.heading);
expect(node?.attributes.heading, BuiltInAttributeKey.h2);
- } else if (itemName == 'Heading 3') {
+ expect(node?.toString(), null);
+ } else if (item.name == 'Heading 3') {
expect(node?.subtype, BuiltInAttributeKey.heading);
expect(node?.attributes.heading, BuiltInAttributeKey.h3);
- } else if (itemName == 'Bulleted list') {
+ expect(node?.toString(), null);
+ } else if (item.name == 'Bulleted list') {
expect(node?.subtype, BuiltInAttributeKey.bulletedList);
- } else if (itemName == 'Checkbox') {
+ } else if (item.name == 'Checkbox') {
expect(node?.subtype, BuiltInAttributeKey.checkbox);
expect(node?.attributes.check, false);
- } else if (itemName == 'Quote') {
- expect(node?.subtype, BuiltInAttributeKey.quote);
}
}
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor/test/service/internal_key_event_handlers/markdown_syntax_to_styled_text_handler_test.dart b/frontend/appflowy_flutter/packages/appflowy_editor/test/service/internal_key_event_handlers/markdown_syntax_to_styled_text_handler_test.dart
deleted file mode 100644
index f39d58e6a3..0000000000
--- a/frontend/appflowy_flutter/packages/appflowy_editor/test/service/internal_key_event_handlers/markdown_syntax_to_styled_text_handler_test.dart
+++ /dev/null
@@ -1,277 +0,0 @@
-import 'package:appflowy_editor/appflowy_editor.dart';
-import 'package:appflowy_editor/src/extensions/text_node_extensions.dart';
-import 'package:flutter/services.dart';
-import 'package:flutter_test/flutter_test.dart';
-import '../../infra/test_editor.dart';
-
-void main() async {
- setUpAll(() {
- TestWidgetsFlutterBinding.ensureInitialized();
- });
-
- group('markdown_syntax_to_styled_text_handler.dart', () {
- group('convert double asterisks to bold', () {
- Future<void> insertAsterisk(
- EditorWidgetTester editor, {
- int repeat = 1,
- }) async {
- for (var i = 0; i < repeat; i++) {
- await editor.pressLogicKey(
- LogicalKeyboardKey.asterisk,
- isShiftPressed: true,
- );
- }
- }
-
- testWidgets('**AppFlowy** to bold AppFlowy', (tester) async {
- const text = '**AppFlowy*';
- final editor = tester.editor..insertTextNode('');
- await editor.startTesting();
- await editor.updateSelection(
- Selection.single(path: [0], startOffset: 0),
- );
- final textNode = editor.nodeAtPath([0]) as TextNode;
- for (var i = 0; i < text.length; i++) {
- await editor.insertText(textNode, text[i], i);
- }
- await insertAsterisk(editor);
- final allBold = textNode.allSatisfyBoldInSelection(
- Selection.single(
- path: [0],
- startOffset: 0,
- endOffset: textNode.toPlainText().length,
- ),
- );
- expect(allBold, true);
- expect(textNode.toPlainText(), 'AppFlowy');
- });
-
- testWidgets('App**Flowy** to bold AppFlowy', (tester) async {
- const text = 'App**Flowy*';
- final editor = tester.editor..insertTextNode('');
- await editor.startTesting();
- await editor.updateSelection(
- Selection.single(path: [0], startOffset: 0),
- );
- final textNode = editor.nodeAtPath([0]) as TextNode;
- for (var i = 0; i < text.length; i++) {
- await editor.insertText(textNode, text[i], i);
- }
- await insertAsterisk(editor);
- final allBold = textNode.allSatisfyBoldInSelection(
- Selection.single(
- path: [0],
- startOffset: 3,
- endOffset: textNode.toPlainText().length,
- ),
- );
- expect(allBold, true);
- expect(textNode.toPlainText(), 'AppFlowy');
- });
-
- testWidgets('***AppFlowy** to bold *AppFlowy', (tester) async {
- const text = '***AppFlowy*';
- final editor = tester.editor..insertTextNode('');
- await editor.startTesting();
- await editor.updateSelection(
- Selection.single(path: [0], startOffset: 0),
- );
- final textNode = editor.nodeAtPath([0]) as TextNode;
- for (var i = 0; i < text.length; i++) {
- await editor.insertText(textNode, text[i], i);
- }
- await insertAsterisk(editor);
- final allBold = textNode.allSatisfyBoldInSelection(
- Selection.single(
- path: [0],
- startOffset: 1,
- endOffset: textNode.toPlainText().length,
- ),
- );
- expect(allBold, true);
- expect(textNode.toPlainText(), '*AppFlowy');
- });
-
- testWidgets('**AppFlowy** application to bold AppFlowy only',
- (tester) async {
- const boldText = '**AppFlowy*';
- final editor = tester.editor..insertTextNode('');
- await editor.startTesting();
- await editor.updateSelection(
- Selection.single(path: [0], startOffset: 0),
- );
- final textNode = editor.nodeAtPath([0]) as TextNode;
-
- for (var i = 0; i < boldText.length; i++) {
- await editor.insertText(textNode, boldText[i], i);
- }
- await insertAsterisk(editor);
- final boldTextLength = boldText.replaceAll('*', '').length;
- final appFlowyBold = textNode.allSatisfyBoldInSelection(
- Selection.single(
- path: [0],
- startOffset: 0,
- endOffset: boldTextLength,
- ),
- );
- expect(appFlowyBold, true);
- expect(textNode.toPlainText(), 'AppFlowy');
- });
-
- testWidgets('**** nothing changes', (tester) async {
- const text = '***';
- final editor = tester.editor..insertTextNode('');
- await editor.startTesting();
- await editor.updateSelection(
- Selection.single(path: [0], startOffset: 0),
- );
- final textNode = editor.nodeAtPath([0]) as TextNode;
- for (var i = 0; i < text.length; i++) {
- await editor.insertText(textNode, text[i], i);
- }
- await insertAsterisk(editor);
- final allBold = textNode.allSatisfyBoldInSelection(
- Selection.single(
- path: [0],
- startOffset: 0,
- endOffset: textNode.toPlainText().length,
- ),
- );
- expect(allBold, false);
- expect(textNode.toPlainText(), text);
- });
- });
-
- group('convert double underscores to bold', () {
- Future<void> insertUnderscore(
- EditorWidgetTester editor, {
- int repeat = 1,
- }) async {
- for (var i = 0; i < repeat; i++) {
- await editor.pressLogicKey(
- LogicalKeyboardKey.underscore,
- isShiftPressed: true,
- );
- }
- }
-
- testWidgets('__AppFlowy__ to bold AppFlowy', (tester) async {
- const text = '__AppFlowy_';
- final editor = tester.editor..insertTextNode('');
- await editor.startTesting();
- await editor.updateSelection(
- Selection.single(path: [0], startOffset: 0),
- );
- final textNode = editor.nodeAtPath([0]) as TextNode;
- for (var i = 0; i < text.length; i++) {
- await editor.insertText(textNode, text[i], i);
- }
- await insertUnderscore(editor);
- final allBold = textNode.allSatisfyBoldInSelection(
- Selection.single(
- path: [0],
- startOffset: 0,
- endOffset: textNode.toPlainText().length,
- ),
- );
- expect(allBold, true);
- expect(textNode.toPlainText(), 'AppFlowy');
- });
-
- testWidgets('App__Flowy__ to bold AppFlowy', (tester) async {
- const text = 'App__Flowy_';
- final editor = tester.editor..insertTextNode('');
- await editor.startTesting();
- await editor.updateSelection(
- Selection.single(path: [0], startOffset: 0),
- );
- final textNode = editor.nodeAtPath([0]) as TextNode;
- for (var i = 0; i < text.length; i++) {
- await editor.insertText(textNode, text[i], i);
- }
- await insertUnderscore(editor);
- final allBold = textNode.allSatisfyBoldInSelection(
- Selection.single(
- path: [0],
- startOffset: 3,
- endOffset: textNode.toPlainText().length,
- ),
- );
- expect(allBold, true);
- expect(textNode.toPlainText(), 'AppFlowy');
- });
-
- testWidgets('___AppFlowy__ to bold _AppFlowy', (tester) async {
- const text = '___AppFlowy_';
- final editor = tester.editor..insertTextNode('');
- await editor.startTesting();
- await editor.updateSelection(
- Selection.single(path: [0], startOffset: 0),
- );
- final textNode = editor.nodeAtPath([0]) as TextNode;
- for (var i = 0; i < text.length; i++) {
- await editor.insertText(textNode, text[i], i);
- }
- await insertUnderscore(editor);
- final allBold = textNode.allSatisfyBoldInSelection(
- Selection.single(
- path: [0],
- startOffset: 1,
- endOffset: textNode.toPlainText().length,
- ),
- );
- expect(allBold, true);
- expect(textNode.toPlainText(), '_AppFlowy');
- });
-
- testWidgets('__AppFlowy__ application to bold AppFlowy only',
- (tester) async {
- const boldText = '__AppFlowy_';
- final editor = tester.editor..insertTextNode('');
- await editor.startTesting();
- await editor.updateSelection(
- Selection.single(path: [0], startOffset: 0),
- );
- final textNode = editor.nodeAtPath([0]) as TextNode;
-
- for (var i = 0; i < boldText.length; i++) {
- await editor.insertText(textNode, boldText[i], i);
- }
- await insertUnderscore(editor);
- final boldTextLength = boldText.replaceAll('_', '').length;
- final appFlowyBold = textNode.allSatisfyBoldInSelection(
- Selection.single(
- path: [0],
- startOffset: 0,
- endOffset: boldTextLength,
- ),
- );
- expect(appFlowyBold, true);
- expect(textNode.toPlainText(), 'AppFlowy');
- });
-
- testWidgets('____ nothing changes', (tester) async {
- const text = '___';
- final editor = tester.editor..insertTextNode('');
- await editor.startTesting();
- await editor.updateSelection(
- Selection.single(path: [0], startOffset: 0),
- );
- final textNode = editor.nodeAtPath([0]) as TextNode;
- for (var i = 0; i < text.length; i++) {
- await editor.insertText(textNode, text[i], i);
- }
- await insertUnderscore(editor);
- final allBold = textNode.allSatisfyBoldInSelection(
- Selection.single(
- path: [0],
- startOffset: 0,
- endOffset: textNode.toPlainText().length,
- ),
- );
- expect(allBold, false);
- expect(textNode.toPlainText(), text);
- });
- });
- });
-}
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor/test/service/internal_key_event_handlers/markdown_syntax_to_styled_text_test.dart b/frontend/appflowy_flutter/packages/appflowy_editor/test/service/internal_key_event_handlers/markdown_syntax_to_styled_text_test.dart
index 662c7982b4..219fd07568 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor/test/service/internal_key_event_handlers/markdown_syntax_to_styled_text_test.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor/test/service/internal_key_event_handlers/markdown_syntax_to_styled_text_test.dart
@@ -257,4 +257,192 @@ void main() async {
});
});
});
+
+ group('convert double asterisk to bold', () {
+ Future<void> insertAsterisk(
+ EditorWidgetTester editor, {
+ int repeat = 1,
+ }) async {
+ for (var i = 0; i < repeat; i++) {
+ await editor.pressLogicKey(
+ LogicalKeyboardKey.digit8,
+ isShiftPressed: true,
+ );
+ }
+ }
+
+ testWidgets('**AppFlowy** to bold AppFlowy', ((widgetTester) async {
+ const text = '**AppFlowy*';
+ final editor = widgetTester.editor..insertTextNode('');
+
+ await editor.startTesting();
+ await editor.updateSelection(Selection.single(path: [0], startOffset: 0));
+ final textNode = editor.nodeAtPath([0]) as TextNode;
+ for (var i = 0; i < text.length; i++) {
+ await editor.insertText(textNode, text[i], i);
+ }
+
+ await insertAsterisk(editor);
+
+ final allBold = textNode.allSatisfyBoldInSelection(Selection.single(
+ path: [0], startOffset: 0, endOffset: textNode.toPlainText().length));
+
+ expect(allBold, true);
+ expect(textNode.toPlainText(), 'AppFlowy');
+ }));
+
+ testWidgets('App**Flowy** to bold AppFlowy', ((widgetTester) async {
+ const text = 'App**Flowy*';
+ final editor = widgetTester.editor..insertTextNode('');
+
+ await editor.startTesting();
+ await editor.updateSelection(Selection.single(path: [0], startOffset: 0));
+ final textNode = editor.nodeAtPath([0]) as TextNode;
+ for (var i = 0; i < text.length; i++) {
+ await editor.insertText(textNode, text[i], i);
+ }
+
+ await insertAsterisk(editor);
+
+ final allBold = textNode.allSatisfyBoldInSelection(Selection.single(
+ path: [0], startOffset: 3, endOffset: textNode.toPlainText().length));
+
+ expect(allBold, true);
+ expect(textNode.toPlainText(), 'AppFlowy');
+ }));
+
+ testWidgets('***AppFlowy** to bold *AppFlowy', ((widgetTester) async {
+ const text = '***AppFlowy*';
+ final editor = widgetTester.editor..insertTextNode('');
+
+ await editor.startTesting();
+ await editor.updateSelection(Selection.single(path: [0], startOffset: 0));
+ final textNode = editor.nodeAtPath([0]) as TextNode;
+ for (var i = 0; i < text.length; i++) {
+ await editor.insertText(textNode, text[i], i);
+ }
+
+ await insertAsterisk(editor);
+
+ final allBold = textNode.allSatisfyBoldInSelection(Selection.single(
+ path: [0], startOffset: 1, endOffset: textNode.toPlainText().length));
+
+ expect(allBold, true);
+ expect(textNode.toPlainText(), '*AppFlowy');
+ }));
+
+ testWidgets('**** nothing changes', ((widgetTester) async {
+ const text = '***';
+ final editor = widgetTester.editor..insertTextNode('');
+
+ await editor.startTesting();
+ await editor.updateSelection(Selection.single(path: [0], startOffset: 0));
+ final textNode = editor.nodeAtPath([0]) as TextNode;
+ for (var i = 0; i < text.length; i++) {
+ await editor.insertText(textNode, text[i], i);
+ }
+
+ await insertAsterisk(editor);
+
+ final allBold = textNode.allSatisfyBoldInSelection(Selection.single(
+ path: [0], startOffset: 0, endOffset: textNode.toPlainText().length));
+
+ expect(allBold, false);
+ expect(textNode.toPlainText(), text);
+ }));
+ });
+
+ group('convert double underscore to bold', () {
+ Future<void> insertUnderscore(
+ EditorWidgetTester editor, {
+ int repeat = 1,
+ }) async {
+ for (var i = 0; i < repeat; i++) {
+ await editor.pressLogicKey(
+ LogicalKeyboardKey.underscore,
+ isShiftPressed: true,
+ );
+ }
+ }
+
+ testWidgets('__AppFlowy__ to bold AppFlowy', ((widgetTester) async {
+ const text = '__AppFlowy_';
+ final editor = widgetTester.editor..insertTextNode('');
+
+ await editor.startTesting();
+ await editor.updateSelection(Selection.single(path: [0], startOffset: 0));
+ final textNode = editor.nodeAtPath([0]) as TextNode;
+ for (var i = 0; i < text.length; i++) {
+ await editor.insertText(textNode, text[i], i);
+ }
+
+ await insertUnderscore(editor);
+
+ final allBold = textNode.allSatisfyBoldInSelection(Selection.single(
+ path: [0], startOffset: 0, endOffset: textNode.toPlainText().length));
+
+ expect(allBold, true);
+ expect(textNode.toPlainText(), 'AppFlowy');
+ }));
+
+ testWidgets('App__Flowy__ to bold AppFlowy', ((widgetTester) async {
+ const text = 'App__Flowy_';
+ final editor = widgetTester.editor..insertTextNode('');
+
+ await editor.startTesting();
+ await editor.updateSelection(Selection.single(path: [0], startOffset: 0));
+ final textNode = editor.nodeAtPath([0]) as TextNode;
+ for (var i = 0; i < text.length; i++) {
+ await editor.insertText(textNode, text[i], i);
+ }
+
+ await insertUnderscore(editor);
+
+ final allBold = textNode.allSatisfyBoldInSelection(Selection.single(
+ path: [0], startOffset: 3, endOffset: textNode.toPlainText().length));
+
+ expect(allBold, true);
+ expect(textNode.toPlainText(), 'AppFlowy');
+ }));
+
+ testWidgets('__*AppFlowy__ to bold *AppFlowy', ((widgetTester) async {
+ const text = '__*AppFlowy_';
+ final editor = widgetTester.editor..insertTextNode('');
+
+ await editor.startTesting();
+ await editor.updateSelection(Selection.single(path: [0], startOffset: 0));
+ final textNode = editor.nodeAtPath([0]) as TextNode;
+ for (var i = 0; i < text.length; i++) {
+ await editor.insertText(textNode, text[i], i);
+ }
+
+ await insertUnderscore(editor);
+
+ final allBold = textNode.allSatisfyBoldInSelection(Selection.single(
+ path: [0], startOffset: 1, endOffset: textNode.toPlainText().length));
+
+ expect(allBold, true);
+ expect(textNode.toPlainText(), '*AppFlowy');
+ }));
+
+ testWidgets('____ nothing changes', ((widgetTester) async {
+ const text = '___';
+ final editor = widgetTester.editor..insertTextNode('');
+
+ await editor.startTesting();
+ await editor.updateSelection(Selection.single(path: [0], startOffset: 0));
+ final textNode = editor.nodeAtPath([0]) as TextNode;
+ for (var i = 0; i < text.length; i++) {
+ await editor.insertText(textNode, text[i], i);
+ }
+
+ await insertUnderscore(editor);
+
+ final allBold = textNode.allSatisfyBoldInSelection(Selection.single(
+ path: [0], startOffset: 0, endOffset: textNode.toPlainText().length));
+
+ expect(allBold, false);
+ expect(textNode.toPlainText(), text);
+ }));
+ });
}
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor/test/service/internal_key_event_handlers/slash_handler_test.dart b/frontend/appflowy_flutter/packages/appflowy_editor/test/service/internal_key_event_handlers/slash_handler_test.dart
index c00036ba11..a6e08d5fa8 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor/test/service/internal_key_event_handlers/slash_handler_test.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor/test/service/internal_key_event_handlers/slash_handler_test.dart
@@ -29,7 +29,7 @@ void main() async {
);
for (final item in defaultSelectionMenuItems) {
- expect(find.text(item.name()), findsOneWidget);
+ expect(find.text(item.name), findsOneWidget);
}
await editor.updateSelection(Selection.single(path: [1], startOffset: 0));
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/code_block/code_block_shortcut_event.dart b/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/code_block/code_block_shortcut_event.dart
index d23d22a78d..d883c1a632 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/code_block/code_block_shortcut_event.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/code_block/code_block_shortcut_event.dart
@@ -79,7 +79,7 @@ ShortcutEventHandler _pasteHandler = (editorState, event) {
};
SelectionMenuItem codeBlockMenuItem = SelectionMenuItem(
- name: () => 'Code Block',
+ name: 'Code Block',
icon: (editorState, onSelected) => Icon(
Icons.abc,
color: onSelected
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/divider/divider_shortcut_event.dart b/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/divider/divider_shortcut_event.dart
index 2d4ad39bf1..96baec98b5 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/divider/divider_shortcut_event.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/divider/divider_shortcut_event.dart
@@ -34,7 +34,7 @@ ShortcutEventHandler _insertDividerHandler = (editorState, event) {
};
SelectionMenuItem dividerMenuItem = SelectionMenuItem(
- name: () => 'Divider',
+ name: 'Divider',
icon: (editorState, onSelected) => Icon(
Icons.horizontal_rule,
color: onSelected
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/emoji_picker/emoji_menu_item.dart b/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/emoji_picker/emoji_menu_item.dart
index 810d497541..34720d16f4 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/emoji_picker/emoji_menu_item.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/emoji_picker/emoji_menu_item.dart
@@ -5,7 +5,7 @@ import 'package:flutter/services.dart';
import 'emoji_picker.dart';
SelectionMenuItem emojiMenuItem = SelectionMenuItem(
- name: () => 'Emoji',
+ name: 'Emoji',
icon: (editorState, onSelected) => Icon(
Icons.emoji_emotions_outlined,
color: onSelected
diff --git a/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/math_ equation/math_equation_node_widget.dart b/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/math_ equation/math_equation_node_widget.dart
index 5485baa6c2..667ae2374a 100644
--- a/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/math_ equation/math_equation_node_widget.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_editor_plugins/lib/src/math_ equation/math_equation_node_widget.dart
@@ -7,7 +7,7 @@ const String kMathEquationType = 'math_equation';
const String kMathEquationAttr = 'math_equation';
SelectionMenuItem mathEquationMenuItem = SelectionMenuItem(
- name: () => 'Math Equation',
+ name: 'Math Equation',
icon: (editorState, onSelected) => Icon(
Icons.text_fields_rounded,
color: onSelected