diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/text_node_extensions.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/text_node_extensions.dart index d4d7857286..4d8c44b9fa 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/text_node_extensions.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/extensions/text_node_extensions.dart @@ -6,7 +6,7 @@ import 'package:appflowy_editor/src/document/text_delta.dart'; import 'package:appflowy_editor/src/document/built_in_attribute_keys.dart'; extension TextNodeExtension on TextNode { - dynamic getAttributeInSelection(Selection selection, String styleKey) { + T? getAttributeInSelection(Selection selection, String styleKey) { final ops = delta.whereType(); final startOffset = selection.isBackward ? selection.start.offset : selection.end.offset; @@ -29,40 +29,42 @@ extension TextNodeExtension on TextNode { } bool allSatisfyLinkInSelection(Selection selection) => - allSatisfyInSelection(selection, BuiltInAttributeKey.href, (value) { + allSatisfyInSelection(selection, BuiltInAttributeKey.href, (value) { return value != null; }); bool allSatisfyBoldInSelection(Selection selection) => - allSatisfyInSelection(selection, BuiltInAttributeKey.bold, (value) { + allSatisfyInSelection(selection, BuiltInAttributeKey.bold, (value) { return value == true; }); bool allSatisfyItalicInSelection(Selection selection) => - allSatisfyInSelection(selection, BuiltInAttributeKey.italic, (value) { + allSatisfyInSelection(selection, BuiltInAttributeKey.italic, + (value) { return value == true; }); bool allSatisfyUnderlineInSelection(Selection selection) => - allSatisfyInSelection(selection, BuiltInAttributeKey.underline, (value) { + allSatisfyInSelection(selection, BuiltInAttributeKey.underline, + (value) { return value == true; }); bool allSatisfyStrikethroughInSelection(Selection selection) => allSatisfyInSelection(selection, BuiltInAttributeKey.strikethrough, - (value) { + (value) { return value == true; }); bool allSatisfyCodeInSelection(Selection selection) => - allSatisfyInSelection(selection, BuiltInAttributeKey.code, (value) { + allSatisfyInSelection(selection, BuiltInAttributeKey.code, (value) { return value == true; }); bool allSatisfyInSelection( Selection selection, String styleKey, - bool Function(dynamic value) test, + bool Function(T value) test, ) { if (BuiltInAttributeKey.globalStyleKeys.contains(styleKey)) { if (attributes.containsKey(styleKey)) { @@ -127,40 +129,40 @@ extension TextNodesExtension on List { bool allSatisfyBoldInSelection(Selection selection) => allSatisfyInSelection( selection, BuiltInAttributeKey.bold, - (value) => value == true, + (value) => value == true, ); bool allSatisfyItalicInSelection(Selection selection) => allSatisfyInSelection( selection, BuiltInAttributeKey.italic, - (value) => value == true, + (value) => value == true, ); bool allSatisfyUnderlineInSelection(Selection selection) => allSatisfyInSelection( selection, BuiltInAttributeKey.underline, - (value) => value == true, + (value) => value == true, ); bool allSatisfyStrikethroughInSelection(Selection selection) => allSatisfyInSelection( selection, BuiltInAttributeKey.strikethrough, - (value) => value == true, + (value) => value == true, ); bool allSatisfyInSelection( Selection selection, String styleKey, - bool Function(dynamic value) test, + bool Function(T value) test, ) { if (isEmpty) { return false; } if (length == 1) { - return first.allSatisfyInSelection(selection, styleKey, (value) { + return first.allSatisfyInSelection(selection, styleKey, (value) { return test(value); }); } else { diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/render/toolbar/toolbar_item.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/toolbar/toolbar_item.dart index 6407f81cb3..1b531f306b 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/render/toolbar/toolbar_item.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/toolbar/toolbar_item.dart @@ -73,7 +73,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.heading, - (value) => value == BuiltInAttributeKey.h1, + (value) => value == BuiltInAttributeKey.h1, ), handler: (editorState, context) => formatHeading(editorState, BuiltInAttributeKey.h1), @@ -90,7 +90,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.heading, - (value) => value == BuiltInAttributeKey.h2, + (value) => value == BuiltInAttributeKey.h2, ), handler: (editorState, context) => formatHeading(editorState, BuiltInAttributeKey.h2), @@ -107,7 +107,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.heading, - (value) => value == BuiltInAttributeKey.h3, + (value) => value == BuiltInAttributeKey.h3, ), handler: (editorState, context) => formatHeading(editorState, BuiltInAttributeKey.h3), @@ -124,7 +124,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.bold, - (value) => value == true, + (value) => value == true, ), handler: (editorState, context) => formatBold(editorState), ), @@ -140,7 +140,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.italic, - (value) => value == true, + (value) => value == true, ), handler: (editorState, context) => formatItalic(editorState), ), @@ -156,7 +156,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.underline, - (value) => value == true, + (value) => value == true, ), handler: (editorState, context) => formatUnderline(editorState), ), @@ -172,7 +172,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.strikethrough, - (value) => value == true, + (value) => value == true, ), handler: (editorState, context) => formatStrikethrough(editorState), ), @@ -188,7 +188,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.code, - (value) => value == true, + (value) => value == true, ), handler: (editorState, context) => formatEmbedCode(editorState), ), @@ -204,7 +204,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.subtype, - (value) => value == BuiltInAttributeKey.quote, + (value) => value == BuiltInAttributeKey.quote, ), handler: (editorState, context) => formatQuote(editorState), ), @@ -220,7 +220,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.subtype, - (value) => value == BuiltInAttributeKey.bulletedList, + (value) => value == BuiltInAttributeKey.bulletedList, ), handler: (editorState, context) => formatBulletedList(editorState), ), @@ -236,7 +236,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.href, - (value) => value != null, + (value) => value != null, ), handler: (editorState, context) => showLinkMenu(context, editorState), ), @@ -252,7 +252,7 @@ List defaultToolbarItems = [ highlightCallback: (editorState) => _allSatisfy( editorState, BuiltInAttributeKey.backgroundColor, - (value) => value != null, + (value) => value != null, ), handler: (editorState, context) => formatHighlight( editorState, @@ -284,7 +284,7 @@ ToolbarItemValidator _showInBuiltInTextSelection = (editorState) { bool _allSatisfy( EditorState editorState, String styleKey, - bool Function(dynamic value) test, + bool Function(T value) test, ) { final selection = editorState.service.selectionService.currentSelection.value; return selection != null && @@ -333,8 +333,10 @@ void showLinkMenu( final textNode = node.first as TextNode; String? linkText; if (textNode.allSatisfyLinkInSelection(selection)) { - linkText = - textNode.getAttributeInSelection(selection, BuiltInAttributeKey.href); + linkText = textNode.getAttributeInSelection( + selection, + BuiltInAttributeKey.href, + ); } _linkMenuOverlay = OverlayEntry(builder: (context) { return Positioned( diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart index 053d9e542a..0377b9e37c 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart @@ -188,7 +188,7 @@ bool _allSatisfyInSelection( return false; } - return textNodes.allSatisfyInSelection(selection, styleKey, (value) { + return textNodes.allSatisfyInSelection(selection, styleKey, (value) { return value == matchValue; }); } diff --git a/frontend/app_flowy/packages/appflowy_editor/test/extensions/text_node_extensions_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/extensions/text_node_extensions_test.dart new file mode 100644 index 0000000000..bec92362f4 --- /dev/null +++ b/frontend/app_flowy/packages/appflowy_editor/test/extensions/text_node_extensions_test.dart @@ -0,0 +1,10 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + group('TextNodeExtension::', () { + test('description', () { + final selecion = Selection.single(path: [0, 1, 2], startOffset: 0); + }); + }); +} diff --git a/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/toolbar_rich_text_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/toolbar_rich_text_test.dart index c9d9ef9e70..49990b4662 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/toolbar_rich_text_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/render/rich_text/toolbar_rich_text_test.dart @@ -229,7 +229,7 @@ void main() async { node.allSatisfyInSelection( code, BuiltInAttributeKey.code, - (value) { + (value) { return value == true; }, ), @@ -319,7 +319,7 @@ void main() async { node.allSatisfyInSelection( selection, BuiltInAttributeKey.backgroundColor, - (value) { + (value) { return value == blue; }, ), diff --git a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/format_style_handler_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/format_style_handler_test.dart index 0cb4c71600..684e7d21f1 100644 --- a/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/format_style_handler_test.dart +++ b/frontend/app_flowy/packages/appflowy_editor/test/service/internal_key_event_handlers/format_style_handler_test.dart @@ -111,7 +111,7 @@ Future _testUpdateTextStyleByCommandX( textNode.allSatisfyInSelection( selection, matchStyle, - (value) { + (value) { return value == matchValue; }, ), @@ -138,7 +138,7 @@ Future _testUpdateTextStyleByCommandX( textNode.allSatisfyInSelection( selection, matchStyle, - (value) { + (value) { return value == matchValue; }, ), @@ -192,7 +192,7 @@ Future _testUpdateTextStyleByCommandX( endOffset: text.length, ), matchStyle, - (value) { + (value) { return value == matchValue; }, ), @@ -266,7 +266,7 @@ Future _testLinkMenuInSingleTextSelection(WidgetTester tester) async { node.allSatisfyInSelection( selection, BuiltInAttributeKey.href, - (value) => value == link, + (value) => value == link, ), true); @@ -303,7 +303,7 @@ Future _testLinkMenuInSingleTextSelection(WidgetTester tester) async { node.allSatisfyInSelection( selection, BuiltInAttributeKey.href, - (value) => value == link, + (value) => value == link, ), false); }