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.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: support toggle heading (#6598)
Lucasfaa95ffb9c09
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_test_runner_2.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_test_runner_2.dartindex 2178b8346e..ebaed7744f 100644--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_test_runner_2.dart+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_test_runner_2.dart@@ -2,11 +2,13 @@ import 'package:integration_test/integration_test.dart';import 'document_app_lifecycle_test.dart' as document_app_lifecycle_test;import 'document_deletion_test.dart' as document_deletion_test;+import 'document_inline_sub_page_test.dart' as document_inline_sub_page_test;import 'document_option_action_test.dart' as document_option_action_test;import 'document_title_test.dart' as document_title_test;import 'document_with_date_reminder_test.dart'as document_with_date_reminder_test;-import 'document_inline_sub_page_test.dart' as document_inline_sub_page_test;+import 'document_with_toggle_heading_block_test.dart'+ as document_with_toggle_heading_block_test;void main() {IntegrationTestWidgetsFlutterBinding.ensureInitialized();@@ -20,4 +22,5 @@ void main() {document_deletion_test.main();document_option_action_test.main();document_inline_sub_page_test.main();+ document_with_toggle_heading_block_test.main();}diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_with_toggle_heading_block_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_with_toggle_heading_block_test.dartnew file mode 100644index 0000000000..ae6f020973--- /dev/null+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_with_toggle_heading_block_test.dart@@ -0,0 +1,82 @@+import 'package:appflowy/generated/locale_keys.g.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';+import 'package:easy_localization/easy_localization.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:integration_test/integration_test.dart';++import '../../shared/util.dart';++const String _heading1 = 'Heading 1';+const String _heading2 = 'Heading 2';+const String _heading3 = 'Heading 3';++void main() {+ IntegrationTestWidgetsFlutterBinding.ensureInitialized();++ group('toggle heading block test:', () {+ testWidgets('insert toggle heading 1 - 3 block', (tester) async {+ await tester.initializeAppFlowy();+ await tester.tapAnonymousSignInButton();++ await tester.createNewPageWithNameUnderParent(+ name: 'toggle heading block test',+ );++ for (var i = 1; i <= 3; i++) {+ await tester.editor.tapLineOfEditorAt(0);+ await _insertToggleHeadingBlockInDocument(tester, i);+ await tester.pumpAndSettle();+ expect(+ find.byWidgetPredicate(+ (widget) =>+ widget is ToggleListBlockComponentWidget &&+ widget.node.attributes[ToggleListBlockKeys.level] == i,+ ),+ findsOneWidget,+ );+ }+ });++ testWidgets('insert toggle heading 1 - 3 block by shortcuts',+ (tester) async {+ await tester.initializeAppFlowy();+ await tester.tapAnonymousSignInButton();++ await tester.createNewPageWithNameUnderParent(+ name: 'toggle heading block test',+ );++ await tester.editor.tapLineOfEditorAt(0);+ await tester.ime.insertText('# > $_heading1\n');+ await tester.ime.insertText('## > $_heading2\n');+ await tester.ime.insertText('### > $_heading3\n');+ await tester.ime.insertText('> # $_heading1\n');+ await tester.ime.insertText('> ## $_heading2\n');+ await tester.ime.insertText('> ### $_heading3\n');+ await tester.pumpAndSettle();++ expect(+ find.byType(ToggleListBlockComponentWidget),+ findsNWidgets(6),+ );+ });+ });+}++Future<void> _insertToggleHeadingBlockInDocument(+ WidgetTester tester,+ int level,+) async {+ final name = switch (level) {+ 1 => LocaleKeys.document_slashMenu_name_toggleHeading1.tr(),+ 2 => LocaleKeys.document_slashMenu_name_toggleHeading2.tr(),+ 3 => LocaleKeys.document_slashMenu_name_toggleHeading3.tr(),+ _ => throw Exception('Invalid level: $level'),+ };+ await tester.editor.showSlashMenu();+ await tester.editor.tapSlashMenuItemWithName(+ name,+ offset: 100,+ );+ await tester.pumpAndSettle();+}diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_with_toggle_list_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_with_toggle_list_test.dartindex 0f3bab2f8e..f4f1be8c78 100644--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_with_toggle_list_test.dart+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_with_toggle_list_test.dart@@ -214,5 +214,54 @@ void main() {expectToggleListOpened();});++ Future<void> prepareToggleHeadingBlock(+ WidgetTester tester,+ String text,+ ) async {+ await tester.initializeAppFlowy();+ await tester.tapAnonymousSignInButton();++ await tester.createNewPageWithNameUnderParent();++ await tester.editor.tapLineOfEditorAt(0);+ await tester.ime.insertText(text);+ }++ testWidgets('> + # to toggle heading 1 block', (tester) async {+ await prepareToggleHeadingBlock(tester, '> # Hello');+ final editorState = tester.editor.getCurrentEditorState();+ final node = editorState.getNodeAtPath([0])!;+ expect(node.type, ToggleListBlockKeys.type);+ expect(node.attributes[ToggleListBlockKeys.level], 1);+ expect(node.delta!.toPlainText(), 'Hello');+ });++ testWidgets('> + ### to toggle heading 3 block', (tester) async {+ await prepareToggleHeadingBlock(tester, '> ### Hello');+ final editorState = tester.editor.getCurrentEditorState();+ final node = editorState.getNodeAtPath([0])!;+ expect(node.type, ToggleListBlockKeys.type);+ expect(node.attributes[ToggleListBlockKeys.level], 3);+ expect(node.delta!.toPlainText(), 'Hello');+ });++ testWidgets('# + > to toggle heading 1 block', (tester) async {+ await prepareToggleHeadingBlock(tester, '# > Hello');+ final editorState = tester.editor.getCurrentEditorState();+ final node = editorState.getNodeAtPath([0])!;+ expect(node.type, ToggleListBlockKeys.type);+ expect(node.attributes[ToggleListBlockKeys.level], 1);+ expect(node.delta!.toPlainText(), 'Hello');+ });++ testWidgets('### + > to toggle heading 3 block', (tester) async {+ await prepareToggleHeadingBlock(tester, '### > Hello');+ final editorState = tester.editor.getCurrentEditorState();+ final node = editorState.getNodeAtPath([0])!;+ expect(node.type, ToggleListBlockKeys.type);+ expect(node.attributes[ToggleListBlockKeys.level], 3);+ expect(node.delta!.toPlainText(), 'Hello');+ });});}diff --git a/frontend/appflowy_flutter/integration_test/shared/common_operations.dart b/frontend/appflowy_flutter/integration_test/shared/common_operations.dartindex cab8faaf35..71b54d53a2 100644--- a/frontend/appflowy_flutter/integration_test/shared/common_operations.dart+++ b/frontend/appflowy_flutter/integration_test/shared/common_operations.dart@@ -214,7 +214,7 @@ extension CommonOperations on WidgetTester {of: find.byType(ViewMoreActionPopover),matching: find.byFlowySvg(FlowySvgs.workspace_three_dots_s),);- await tapButton(optionButton, warnIfMissed: true);+ await tapButton(optionButton);}/// Tap the delete page button.diff --git a/frontend/appflowy_flutter/lib/core/network_monitor.dart b/frontend/appflowy_flutter/lib/core/network_monitor.dartindex 8959db42b9..3d01204921 100644--- a/frontend/appflowy_flutter/lib/core/network_monitor.dart+++ b/frontend/appflowy_flutter/lib/core/network_monitor.dart@@ -1,9 +1,9 @@import 'dart:async';+import 'package:appflowy_backend/dispatch/dispatch.dart';+import 'package:appflowy_backend/log.dart';import 'package:appflowy_backend/protobuf/flowy-user/user_setting.pb.dart';import 'package:connectivity_plus/connectivity_plus.dart';-import 'package:appflowy_backend/log.dart';-import 'package:appflowy_backend/dispatch/dispatch.dart';import 'package:flutter/services.dart';class NetworkListener {diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dartindex 1bbb6bd846..043b618634 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart@@ -261,6 +261,8 @@ Map<String, BlockComponentBuilder> _buildBlockComponentBuilderMap(ToggleListBlockKeys.type: _buildToggleListBlockComponentBuilder(context,configuration,+ styleCustomizer,+ customHeadingPadding,),OutlineBlockKeys.type: _buildOutlineBlockComponentBuilder(context,@@ -574,9 +576,47 @@ SmartEditBlockComponentBuilder _buildSmartEditBlockComponentBuilder(ToggleListBlockComponentBuilder _buildToggleListBlockComponentBuilder(BuildContext context,BlockComponentConfiguration configuration,+ EditorStyleCustomizer styleCustomizer,+ EdgeInsets? customHeadingPadding,) {return ToggleListBlockComponentBuilder(- configuration: configuration,+ configuration: configuration.copyWith(+ padding: (node) {+ if (customHeadingPadding != null) {+ return customHeadingPadding;+ }++ if (UniversalPlatform.isMobile) {+ final pageStyle = context.read<DocumentPageStyleBloc>().state;+ final factor = pageStyle.fontLayout.factor;+ final headingPaddings =+ pageStyle.lineHeightLayout.headingPaddings.map((e) => e * factor);+ int level = node.attributes[HeadingBlockKeys.level] ?? 6;+ level = level.clamp(1, 6);+ return EdgeInsets.only(top: headingPaddings.elementAt(level - 1));+ }++ return const EdgeInsets.only(top: 12.0, bottom: 4.0);+ },+ textStyle: (node) {+ final level = node.attributes[ToggleListBlockKeys.level] as int?;+ if (level == null) {+ return configuration.textStyle(node);+ }+ return styleCustomizer.headingStyleBuilder(level);+ },+ placeholderText: (node) {+ int? level = node.attributes[ToggleListBlockKeys.level];+ if (level == null) {+ return configuration.placeholderText(node);+ }+ level = level.clamp(1, 6);+ return LocaleKeys.blockPlaceholders_heading.tr(+ args: [level.toString()],+ );+ },+ ),+ textStyleBuilder: (level) => styleCustomizer.headingStyleBuilder(level),);}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dartindex 83a9775068..8f9a51b4bc 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart@@ -374,6 +374,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>heading1SlashMenuItem,heading2SlashMenuItem,heading3SlashMenuItem,+imageSlashMenuItem,bulletedListSlashMenuItem,numberedListSlashMenuItem,@@ -393,6 +394,9 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>mathEquationSlashMenuItem,codeBlockSlashMenuItem,toggleListSlashMenuItem,+ toggleHeading1SlashMenuItem,+ toggleHeading2SlashMenuItem,+ toggleHeading3SlashMenuItem,emojiSlashMenuItem,dateOrReminderSlashMenuItem,photoGallerySlashMenuItem,diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_option_cubit.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_option_cubit.dartindex c047ff6f70..86a462667c 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_option_cubit.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_option_cubit.dart@@ -184,6 +184,15 @@ class BlockActionOptionCubit extends Cubit<BlockActionOptionState> {.toList();Log.info('turnIntoBlock selectedNodes $selectedNodes');+ // try to turn into a single toggle heading block+ if (await turnIntoSingleToggleHeading(+ type: toType,+ selectedNodes: selectedNodes,+ level: level,+ )) {+ return true;+ }+final insertedNode = <Node>[];for (final node in selectedNodes) {@@ -195,6 +204,8 @@ class BlockActionOptionCubit extends Cubit<BlockActionOptionState> {type: type,attributes: {if (toType == HeadingBlockKeys.type) HeadingBlockKeys.level: level,+ if (toType == ToggleListBlockKeys.type)+ ToggleListBlockKeys.level: level,if (toType == TodoListBlockKeys.type)TodoListBlockKeys.checked: false,blockComponentBackgroundColor:@@ -233,6 +244,99 @@ class BlockActionOptionCubit extends Cubit<BlockActionOptionState> {return true;}+ // turn a single node into toggle heading block+ // 1. find the sibling nodes after the selected node until+ // meet the first node that contains level and its value is greater or equal to the level+ // 2. move the found nodes in the selected node+ //+ // example:+ // Toggle Heading 1 <- selected node+ // - bulleted item 1+ // - bulleted item 2+ // - bulleted item 3+ // Heading 1+ // - paragraph 1+ // - paragraph 2+ // when turning "Toggle Heading 1" into toggle heading, the bulleted items will be moved into the toggle heading+ Future<bool> turnIntoSingleToggleHeading({+ required String type,+ required List<Node> selectedNodes,+ int? level,+ Delta? delta,+ Selection? afterSelection,+ }) async {+ // only support turn a single node into toggle heading block+ if (type != ToggleListBlockKeys.type ||+ selectedNodes.length != 1 ||+ level == null) {+ return false;+ }++ // find the sibling nodes after the selected node until+ final insertedNodes = <Node>[];+ final node = selectedNodes.first;+ Path path = node.path.next;+ Node? nextNode = editorState.getNodeAtPath(path);+ while (nextNode != null) {+ if (nextNode.type == HeadingBlockKeys.type &&+ nextNode.attributes[HeadingBlockKeys.level] != null &&+ nextNode.attributes[HeadingBlockKeys.level]! <= level) {+ break;+ }++ if (nextNode.type == ToggleListBlockKeys.type &&+ nextNode.attributes[ToggleListBlockKeys.level] != null &&+ nextNode.attributes[ToggleListBlockKeys.level]! <= level) {+ break;+ }++ insertedNodes.add(nextNode);++ path = path.next;+ nextNode = editorState.getNodeAtPath(path);+ }++ Log.info('insertedNodes $insertedNodes');++ Log.info(+ 'Turn into block: from ${node.type} to $type',+ );++ final afterNode = node.copyWith(+ type: type,+ attributes: {+ ToggleListBlockKeys.level: level,+ ToggleListBlockKeys.collapsed:+ node.attributes[ToggleListBlockKeys.collapsed] ?? false,+ blockComponentBackgroundColor:+ node.attributes[blockComponentBackgroundColor],+ blockComponentTextDirection:+ node.attributes[blockComponentTextDirection],+ blockComponentDelta: (delta ?? node.delta ?? Delta()).toJson(),+ },+ children: [+ ...node.children,+ ...insertedNodes.map((e) => e.copyWith()),+ ],+ );++ final transaction = editorState.transaction;+ transaction.insertNode(+ node.path,+ afterNode,+ );+ transaction.deleteNodes([+ node,+ ...insertedNodes,+ ]);+ if (afterSelection != null) {+ transaction.afterSelection = afterSelection;+ }+ await editorState.apply(transaction);++ return true;+ }+Selection? calculateTurnIntoSelection(Node selectedNode,Selection? beforeSelection,diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option/option_actions.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option/option_actions.dartindex 8aa2807548..09b7581918 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option/option_actions.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option/option_actions.dart@@ -28,6 +28,7 @@ enum EditorOptionActionType {BulletedListBlockKeys.type,NumberedListBlockKeys.type,TodoListBlockKeys.type,+ ToggleListBlockKeys.type,};case EditorOptionActionType.color:return {diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option/turn_into_option_action.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option/turn_into_option_action.dartindex 60ccbea800..915189774a 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option/turn_into_option_action.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option/turn_into_option_action.dart@@ -96,7 +96,29 @@ class TurnIntoOptionMenu extends StatelessWidget {final children = <Widget>[];for (final type in EditorOptionActionType.turnInto.supportTypes) {- if (type != HeadingBlockKeys.type) {+ if (type == ToggleListBlockKeys.type) {+ // toggle list block and toggle heading block are the same type,+ // but they have different attributes.++ // toggle list block+ children.add(+ _TurnInfoButton(+ type: type,+ node: node,+ ),+ );++ // toggle heading block+ for (final i in [1, 2, 3]) {+ children.add(+ _TurnInfoButton(+ type: type,+ node: node,+ level: i,+ ),+ );+ }+ } else if (type != HeadingBlockKeys.type) {children.add(_TurnInfoButton(type: type,@@ -104,7 +126,6 @@ class TurnIntoOptionMenu extends StatelessWidget {),);} else {- // support h46for (final i in [1, 2, 3]) {children.add(_TurnInfoButton(@@ -179,6 +200,13 @@ class _TurnInfoButton extends StatelessWidget {}}+ if (node.type == ToggleListBlockKeys.type) {+ final nodeLevel = node.attributes[ToggleListBlockKeys.level];+ if (level != nodeLevel) {+ return null;+ }+ }+return const FlowySvg(FlowySvgs.workspace_selected_s,blendMode: null,@@ -199,7 +227,6 @@ class _TurnInfoButton extends StatelessWidget {return FlowySvgs.slash_menu_icon_h2_s;case 3:return FlowySvgs.slash_menu_icon_h3_s;- // support h4h6default:return FlowySvgs.slash_menu_icon_text_s;}@@ -213,6 +240,17 @@ class _TurnInfoButton extends StatelessWidget {return FlowySvgs.slash_menu_icon_checkbox_s;} else if (type == CalloutBlockKeys.type) {return FlowySvgs.slash_menu_icon_callout_s;+ } else if (type == ToggleListBlockKeys.type) {+ switch (level) {+ case 1:+ return FlowySvgs.slash_menu_icon_h1_s;+ case 2:+ return FlowySvgs.slash_menu_icon_h2_s;+ case 3:+ return FlowySvgs.slash_menu_icon_h3_s;+ default:+ return FlowySvgs.slash_menu_icon_toggle_s;+ }}throw UnimplementedError('Unsupported block type: $type');@@ -246,6 +284,17 @@ class _TurnInfoButton extends StatelessWidget {return LocaleKeys.document_slashMenu_name_todoList.tr();case CalloutBlockKeys.type:return LocaleKeys.document_slashMenu_name_callout.tr();+ case ToggleListBlockKeys.type:+ switch (level) {+ case 1:+ return LocaleKeys.document_slashMenu_name_toggleHeading1.tr();+ case 2:+ return LocaleKeys.document_slashMenu_name_toggleHeading2.tr();+ case 3:+ return LocaleKeys.document_slashMenu_name_toggleHeading3.tr();+ default:+ return LocaleKeys.document_slashMenu_name_toggleList.tr();+ }}throw UnimplementedError('Unsupported block type: $type');diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/plugins.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/plugins.dartindex 6dd8e4d4b7..a4927f566d 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/plugins.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/plugins.dart@@ -62,4 +62,4 @@ export 'table/table_menu.dart';export 'table/table_option_action.dart';export 'todo_list/todo_list_icon.dart';export 'toggle/toggle_block_component.dart';-export 'toggle/toggle_block_shortcut_event.dart';+export 'toggle/toggle_block_shortcuts.dart';diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/character_shortcuts.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/character_shortcuts.dartindex aba1b68a28..8888d3ea1b 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/character_shortcuts.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/character_shortcuts.dart@@ -3,6 +3,8 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/base/formaimport 'package:appflowy/plugins/document/presentation/editor_plugins/base/page_reference_commands.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/callout/callout_block_shortcuts.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/shortcuts/heading_block_shortcuts.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/shortcuts/numbered_list_block_shortcuts.dart';import 'package:appflowy/plugins/document/presentation/editor_style.dart';import 'package:appflowy/plugins/inline_actions/inline_actions_command.dart';import 'package:appflowy/plugins/inline_actions/inline_actions_service.dart';@@ -40,11 +42,16 @@ List<CharacterShortcutEvent> buildCharacterShortcutEvents(customFormatGreaterEqual,+ customFormatNumberToNumberedList,+ customFormatSignToHeading,+...standardCharacterShortcutEvents..removeWhere((shortcut) => [slashCommand, // Remove default slash commandformatGreaterEqual, // Overridden by customFormatGreaterEqual+ formatNumberToNumberedList, // Overridden by customFormatNumberToNumberedList+ formatSignToHeading, // Overridden by customFormatSignToHeading].contains(shortcut),),diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/command_shortcuts.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/command_shortcuts.dartindex 094f14dedc..46ded666ff 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/command_shortcuts.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/command_shortcuts.dart@@ -17,6 +17,7 @@ final List<CommandShortcutEvent> defaultCommandShortcutEvents = [List<CommandShortcutEvent> commandShortcutEvents = [customExitEditingCommand,backspaceToTitle,+ removeToggleHeadingStyle,arrowUpToTitle,arrowLeftToTitle,diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/heading_block_shortcuts.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/heading_block_shortcuts.dartnew file mode 100644index 0000000000..6ecdd8a90e--- /dev/null+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/heading_block_shortcuts.dart@@ -0,0 +1,50 @@+import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';+import 'package:appflowy_editor/appflowy_editor.dart';++/// Convert '# ' to bulleted list+///+/// - support+/// - desktop+/// - mobile+/// - web+///+CharacterShortcutEvent customFormatSignToHeading = CharacterShortcutEvent(+ key: 'format sign to heading list',+ character: ' ',+ handler: (editorState) async => formatMarkdownSymbol(+ editorState,+ (node) => true,+ (_, text, selection) {+ final characters = text.split('');+ // only supports h1 to h6 levels+ // if the characters is empty, the every function will return true directly+ return characters.isNotEmpty &&+ characters.every((element) => element == '#') &&+ characters.length < 7;+ },+ (text, node, delta) {+ final numberOfSign = text.split('').length;+ final type = node.type;++ // if current node is toggle block, try to convert it to toggle heading block.+ if (type == ToggleListBlockKeys.type) {+ final collapsed =+ node.attributes[ToggleListBlockKeys.collapsed] as bool?;+ return [+ toggleHeadingNode(+ level: numberOfSign,+ delta: delta.compose(Delta()..delete(numberOfSign)),+ collapsed: collapsed ?? false,+ ),+ ];+ }+ return [+ headingNode(+ level: numberOfSign,+ delta: delta.compose(Delta()..delete(numberOfSign)),+ ),+ if (node.children.isNotEmpty) ...node.children,+ ];+ },+ ),+);diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/numbered_list_block_shortcuts.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/numbered_list_block_shortcuts.dartnew file mode 100644index 0000000000..b0e271fbe8--- /dev/null+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/numbered_list_block_shortcuts.dart@@ -0,0 +1,95 @@+import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';+import 'package:appflowy/shared/patterns/common_patterns.dart';+import 'package:appflowy_editor/appflowy_editor.dart';++/// Convert 'num. ' to bulleted list+///+/// - support+/// - desktop+/// - mobile+///+/// In heading block and toggle heading block, this shortcut will be ignored.+CharacterShortcutEvent customFormatNumberToNumberedList =+ CharacterShortcutEvent(+ key: 'format number to numbered list',+ character: ' ',+ handler: (editorState) async => formatMarkdownSymbol(+ editorState,+ (node) => node.type != NumberedListBlockKeys.type,+ (node, text, selection) {+ final shouldBeIgnored = _shouldBeIgnored(node);+ if (shouldBeIgnored) {+ return false;+ }++ final match = numberedListRegex.firstMatch(text);+ if (match == null) {+ return false;+ }++ final matchText = match.group(0);+ final numberText = match.group(1);++ if (matchText == null || numberText == null) {+ return false;+ }++ // if the previous one is numbered list,+ // we should check the current number is the next number of the previous one+ Node? previous = node.previous;+ int level = 0;+ int? startNumber;+ while (previous != null && previous.type == NumberedListBlockKeys.type) {+ startNumber = previous.attributes[NumberedListBlockKeys.number] as int?;+ level++;+ previous = previous.previous;+ }+ if (startNumber != null) {+ final currentNumber = int.tryParse(numberText);+ if (currentNumber == null || currentNumber != startNumber + level) {+ return false;+ }+ }++ return selection.endIndex == matchText.length;+ },+ (text, node, delta) {+ final match = numberedListRegex.firstMatch(text);+ final matchText = match?.group(0);+ if (matchText == null) {+ return [node];+ }++ final number = matchText.substring(0, matchText.length - 1);+ final composedDelta = delta.compose(+ Delta()..delete(matchText.length),+ );+ return [+ node.copyWith(+ type: NumberedListBlockKeys.type,+ attributes: {+ NumberedListBlockKeys.delta: composedDelta.toJson(),+ NumberedListBlockKeys.number: int.tryParse(number),+ },+ ),+ ];+ },+ ),+);++bool _shouldBeIgnored(Node node) {+ final type = node.type;++ // ignore heading block+ if (type == HeadingBlockKeys.type) {+ return true;+ }++ // ignore toggle heading block+ final level = node.attributes[ToggleListBlockKeys.level] as int?;+ if (type == ToggleListBlockKeys.type && level != null) {+ return true;+ }++ return false;+}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items.dartindex 3380d8184b..7def01d0d6 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items.dart@@ -75,6 +75,62 @@ final heading3SlashMenuItem = SelectionMenuItem(},);+// toggle heading 1 menu item+// heading 1 - 3 menu items+final toggleHeading1SlashMenuItem = SelectionMenuItem(+ // todo: i18n+ getName: () => LocaleKeys.document_slashMenu_name_toggleHeading1.tr(),+ nameBuilder: _slashMenuItemNameBuilder,+ icon: (editorState, isSelected, style) => SelectableSvgWidget(+ data: FlowySvgs.slash_menu_icon_h1_s,+ isSelected: isSelected,+ style: style,+ ),+ keywords: ['toggle heading 1', 'toggle h1', 'toggle heading1'],+ handler: (editorState, _, __) {+ insertNodeAfterSelection(+ editorState,+ toggleHeadingNode(),+ );+ },+);++final toggleHeading2SlashMenuItem = SelectionMenuItem(+ // todo: i18n+ getName: () => LocaleKeys.document_slashMenu_name_toggleHeading2.tr(),+ nameBuilder: _slashMenuItemNameBuilder,+ icon: (editorState, isSelected, style) => SelectableSvgWidget(+ data: FlowySvgs.slash_menu_icon_h2_s,+ isSelected: isSelected,+ style: style,+ ),+ keywords: ['toggle heading 2', 'toggle h2', 'toggle heading2'],+ handler: (editorState, _, __) {+ insertNodeAfterSelection(+ editorState,+ toggleHeadingNode(level: 2),+ );+ },+);++final toggleHeading3SlashMenuItem = SelectionMenuItem(+ // todo: i18n+ getName: () => LocaleKeys.document_slashMenu_name_toggleHeading3.tr(),+ nameBuilder: _slashMenuItemNameBuilder,+ icon: (editorState, isSelected, style) => SelectableSvgWidget(+ data: FlowySvgs.slash_menu_icon_h3_s,+ isSelected: isSelected,+ style: style,+ ),+ keywords: ['toggle heading 3', 'toggle h3', 'toggle heading3'],+ handler: (editorState, _, __) {+ insertNodeAfterSelection(+ editorState,+ toggleHeadingNode(level: 3),+ );+ },+);+// image menu itemfinal imageSlashMenuItem = SelectionMenuItem(getName: () => LocaleKeys.document_slashMenu_name_image.tr(),diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dartindex 73e4a4f39b..8dd7d25841 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart@@ -20,6 +20,11 @@ class ToggleListBlockKeys {/// The value is a bool.static const String collapsed = 'collapsed';++ /// The value is a int.+ ///+ /// If this value is not null, the block represent a toggle heading.+ static const String level = 'level';}Node toggleListBlockNode({@@ -30,17 +35,41 @@ Node toggleListBlockNode({Attributes? attributes,Iterable<Node>? children,}) {+ delta ??= Delta()..insert(text ?? '');return Node(type: ToggleListBlockKeys.type,+ children: children ?? [],attributes: {- ToggleListBlockKeys.collapsed: collapsed,- ToggleListBlockKeys.delta:- (delta ?? (Delta()..insert(text ?? ''))).toJson(),- if (attributes != null) ...attributes,if (textDirection != null)ToggleListBlockKeys.textDirection: textDirection,+ ToggleListBlockKeys.collapsed: collapsed,+ ToggleListBlockKeys.delta: delta.toJson(),+ if (attributes != null) ...attributes,+ },+ );+}++Node toggleHeadingNode({+ int level = 1,+ String? text,+ Delta? delta,+ bool collapsed = false,+ String? textDirection,+ Attributes? attributes,+ Iterable<Node>? children,+}) {+ // only support level 1 - 6+ level = level.clamp(1, 6);+ return toggleListBlockNode(+ text: text,+ delta: delta,+ collapsed: collapsed,+ textDirection: textDirection,+ children: children,+ attributes: {+ if (attributes != null) ...attributes,+ ToggleListBlockKeys.level: level,},- children: children ?? [],);}@@ -57,10 +86,14 @@ class ToggleListBlockComponentBuilder extends BlockComponentBuilder {ToggleListBlockComponentBuilder({super.configuration,this.padding = const EdgeInsets.all(0),+ this.textStyleBuilder,});final EdgeInsets padding;+ /// The text style of the toggle heading block.+ final TextStyle Function(int level)? textStyleBuilder;+@overrideBlockComponentWidget build(BlockComponentContext blockComponentContext) {final node = blockComponentContext.node;@@ -69,6 +102,7 @@ class ToggleListBlockComponentBuilder extends BlockComponentBuilder {node: node,configuration: configuration,padding: padding,+ textStyleBuilder: textStyleBuilder,showActions: showActions(node),actionBuilder: (context, state) => actionBuilder(blockComponentContext,@@ -89,9 +123,11 @@ class ToggleListBlockComponentWidget extends BlockComponentStatefulWidget {super.actionBuilder,super.configuration = const BlockComponentConfiguration(),this.padding = const EdgeInsets.all(0),+ this.textStyleBuilder,});final EdgeInsets padding;+ final TextStyle Function(int level)? textStyleBuilder;@overrideState<ToggleListBlockComponentWidget> createState() =>@@ -135,6 +171,7 @@ class _ToggleListBlockComponentWidgetState);bool get collapsed => node.attributes[ToggleListBlockKeys.collapsed] ?? false;+ int? get level => node.attributes[ToggleListBlockKeys.level] as int?;@overrideWidget build(BuildContext context) {@@ -153,7 +190,9 @@ class _ToggleListBlockComponentWidgetState);Widget child = Container(- color: backgroundColor,+ color: withBackgroundColor || backgroundColor != Colors.transparent+ ? backgroundColor+ : null,width: double.infinity,alignment: alignment,child: Row(@@ -161,44 +200,9 @@ class _ToggleListBlockComponentWidgetStatecrossAxisAlignment: CrossAxisAlignment.start,textDirection: textDirection,children: [- // the emoji picker button for the note- Container(- constraints: const BoxConstraints(minWidth: 26, minHeight: 22),- padding: const EdgeInsets.only(right: 4.0),- child: AnimatedRotation(- turns: collapsed ? 0.0 : 0.25,- duration: const Duration(milliseconds: 200),- child: FlowyIconButton(- width: 18.0,- icon: const Icon(- Icons.arrow_right,- size: 18.0,- ),- onPressed: onCollapsed,- ),- ),- ),-+ _buildExpandIcon(),Flexible(- child: AppFlowyRichText(- key: forwardKey,- delegate: this,- node: widget.node,- editorState: editorState,- placeholderText: placeholderText,- lineHeight: 1.5,- textSpanDecorator: (textSpan) => textSpan.updateTextStyle(- textStyle,- ),- placeholderTextSpanDecorator: (textSpan) =>- textSpan.updateTextStyle(- placeholderTextStyle,- ),- textDirection: textDirection,- textAlign: alignment?.toTextAlign,- cursorColor: editorState.editorStyle.cursorColor,- selectionColor: editorState.editorStyle.selectionColor,- ),+ child: _buildRichText(),),],),@@ -232,6 +236,78 @@ class _ToggleListBlockComponentWidgetStatereturn child;}+ Widget _buildRichText() {+ final textDirection = calculateTextDirection(+ layoutDirection: Directionality.maybeOf(context),+ );+ final level = node.attributes[ToggleListBlockKeys.level];+ return AppFlowyRichText(+ key: forwardKey,+ delegate: this,+ node: widget.node,+ editorState: editorState,+ placeholderText: placeholderText,+ lineHeight: 1.5,+ textSpanDecorator: (textSpan) {+ var result = textSpan.updateTextStyle(textStyle);+ if (level != null) {+ result = result.updateTextStyle(+ widget.textStyleBuilder?.call(level),+ );+ }+ return result;+ },+ placeholderTextSpanDecorator: (textSpan) {+ var result = textSpan.updateTextStyle(textStyle);+ if (level != null && widget.textStyleBuilder != null) {+ result = result.updateTextStyle(+ widget.textStyleBuilder?.call(level),+ );+ }+ return result.updateTextStyle(placeholderTextStyle);+ },+ textDirection: textDirection,+ textAlign: alignment?.toTextAlign,+ cursorColor: editorState.editorStyle.cursorColor,+ selectionColor: editorState.editorStyle.selectionColor,+ );+ }++ Widget _buildExpandIcon() {+ const buttonHeight = 22.0;+ double top = 0.0;++ if (level != null) {+ // top padding * 2 + button height = height of the heading text+ final textStyle = widget.textStyleBuilder?.call(level ?? 1);+ final fontSize = textStyle?.fontSize;+ final lineHeight = textStyle?.height ?? 1.5;+ if (fontSize != null) {+ top = (fontSize * lineHeight - buttonHeight) / 2;+ }+ }++ return Container(+ constraints: const BoxConstraints(+ minWidth: 26,+ minHeight: buttonHeight,+ ),+ padding: EdgeInsets.only(top: top, right: 4.0),+ child: AnimatedRotation(+ turns: collapsed ? 0.0 : 0.25,+ duration: const Duration(milliseconds: 200),+ child: FlowyIconButton(+ width: 20.0,+ icon: const Icon(+ Icons.arrow_right,+ size: 18.0,+ ),+ onPressed: onCollapsed,+ ),+ ),+ );+ }+Future<void> onCollapsed() async {final transaction = editorState.transaction..updateNode(node, {diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcut_event.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcuts.dartsimilarity index 50%rename from frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcut_event.dartrename to frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcuts.dartindex 36c99acb19..f806eaf200 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcut_event.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcuts.dart@@ -1,3 +1,4 @@+import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/block_action_option_cubit.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart';import 'package:appflowy_editor/appflowy_editor.dart';import 'package:flutter/material.dart';@@ -13,20 +14,66 @@ const _greater = '>';/// - web///CharacterShortcutEvent formatGreaterToToggleList = CharacterShortcutEvent(- key: 'format greater to quote',+ key: 'format greater to toggle list',character: ' ',- handler: (editorState) async => formatMarkdownSymbol(+ handler: (editorState) async => _formatGreaterSymbol(editorState,(node) => node.type != ToggleListBlockKeys.type,(_, text, __) => text == _greater,- (_, node, delta) => [- toggleListBlockNode(- delta: delta.compose(Delta()..delete(_greater.length)),- ),- ],+ (text, node, delta, afterSelection) async => _formatGreaterToToggleHeading(+ editorState,+ text,+ node,+ delta,+ afterSelection,+ ),),);+Future<void> _formatGreaterToToggleHeading(+ EditorState editorState,+ String text,+ Node node,+ Delta delta,+ Selection afterSelection,+) async {+ final type = node.type;+ int? level;+ if (type == ToggleListBlockKeys.type) {+ level = node.attributes[ToggleListBlockKeys.level] as int?;+ } else if (type == HeadingBlockKeys.type) {+ level = node.attributes[HeadingBlockKeys.level] as int?;+ }+ delta = delta.compose(Delta()..delete(_greater.length));+ // if the previous block is heading block, convert it to toggle heading block+ if (type == HeadingBlockKeys.type && level != null) {+ final cubit = BlockActionOptionCubit(+ editorState: editorState,+ blockComponentBuilder: {},+ );+ await cubit.turnIntoSingleToggleHeading(+ type: ToggleListBlockKeys.type,+ selectedNodes: [node],+ level: level,+ delta: delta,+ afterSelection: afterSelection,+ );+ return;+ }++ final transaction = editorState.transaction;+ transaction+ ..insertNode(+ node.path,+ toggleListBlockNode(+ delta: delta,+ ),+ )+ ..deleteNode(node);+ transaction.afterSelection = afterSelection;+ await editorState.apply(transaction);+}+/// Press enter key to insert child node inside the toggle list////// - support@@ -146,3 +193,113 @@ CommandShortcutEventHandler _toggleToggleListCommandHandler = (editorState) {editorState.apply(transaction);return KeyEventResult.handled;};++/// Press the backspace at the first position of first line to go to the title+///+/// - support+/// - desktop+/// - web+///+final CommandShortcutEvent removeToggleHeadingStyle = CommandShortcutEvent(+ key: 'remove toggle heading style',+ command: 'backspace',+ getDescription: () => 'remove toggle heading style',+ handler: (editorState) => _removeToggleHeadingStyle(+ editorState: editorState,+ ),+);++// convert the toggle heading block to heading block+KeyEventResult _removeToggleHeadingStyle({+ required EditorState editorState,+}) {+ final selection = editorState.selection;+ if (selection == null ||+ !selection.isCollapsed ||+ selection.start.offset != 0) {+ return KeyEventResult.ignored;+ }++ final node = editorState.getNodeAtPath(selection.start.path);+ if (node == null || node.type != ToggleListBlockKeys.type) {+ return KeyEventResult.ignored;+ }++ final level = node.attributes[ToggleListBlockKeys.level] as int?;+ if (level == null) {+ return KeyEventResult.ignored;+ }++ final transaction = editorState.transaction;+ transaction.updateNode(node, {+ ToggleListBlockKeys.level: null,+ });+ transaction.afterSelection = selection;+ editorState.apply(transaction);++ return KeyEventResult.handled;+}++/// Formats the current node to specified markdown style.+///+/// For example,+/// bulleted list: '- '+/// numbered list: '1. '+/// quote: '" '+/// ...+///+/// The [nodeBuilder] can return a list of nodes, which will be inserted+/// into the document.+/// For example, when converting a bulleted list to a heading and the heading is+/// not allowed to contain children, then the [nodeBuilder] should return a list+/// of nodes, which contains the heading node and the children nodes.+Future<bool> _formatGreaterSymbol(+ EditorState editorState,+ bool Function(Node node) shouldFormat,+ bool Function(+ Node node,+ String text,+ Selection selection,+ ) predicate,+ Future<void> Function(+ String text,+ Node node,+ Delta delta,+ Selection afterSelection,+ ) onFormat,+) async {+ final selection = editorState.selection;+ if (selection == null || !selection.isCollapsed) {+ return false;+ }++ final position = selection.end;+ final node = editorState.getNodeAtPath(position.path);++ if (node == null || !shouldFormat(node)) {+ return false;+ }++ // Get the text from the start of the document until the selection.+ final delta = node.delta;+ if (delta == null) {+ return false;+ }+ final text = delta.toPlainText().substring(0, selection.end.offset);++ // If the text doesn't match the predicate, then we don't want to+ // format it.+ if (!predicate(node, text, selection)) {+ return false;+ }++ final afterSelection = Selection.collapsed(+ Position(+ path: node.path,+ ),+ );++ await onFormat(text, node, delta, afterSelection);++ return true;+}diff --git a/frontend/appflowy_flutter/lib/shared/patterns/common_patterns.dart b/frontend/appflowy_flutter/lib/shared/patterns/common_patterns.dartindex d3738b4349..e7181d8538 100644--- a/frontend/appflowy_flutter/lib/shared/patterns/common_patterns.dart+++ b/frontend/appflowy_flutter/lib/shared/patterns/common_patterns.dart@@ -39,3 +39,6 @@ final macOSVolumesRegex = RegExp(_macOSVolumesPattern);const appflowySharePageLinkPattern =r'^https://appflowy\.com/app/([^/]+)/([^?]+)(?:\?blockId=(.+))?$';final appflowySharePageLinkRegex = RegExp(appflowySharePageLinkPattern);++const _numberedListPattern = r'^(\d+)\.';+final numberedListRegex = RegExp(_numberedListPattern);diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_shortcuts_view.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_shortcuts_view.dartindex 397b73cb3d..87ea9d9260 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_shortcuts_view.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_shortcuts_view.dart@@ -5,7 +5,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/base/strinimport 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/custom_copy_command.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/custom_cut_command.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart';-import 'package:appflowy/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcut_event.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcuts.dart';import 'package:appflowy/workspace/application/settings/shortcuts/settings_shortcuts_cubit.dart';import 'package:appflowy/workspace/application/settings/shortcuts/settings_shortcuts_service.dart';import 'package:appflowy/workspace/presentation/settings/shared/settings_alert_dialog.dart';diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lockindex f8cda142c5..c6e9279c62 100644--- a/frontend/appflowy_flutter/pubspec.lock+++ b/frontend/appflowy_flutter/pubspec.lock@@ -1543,10 +1543,10 @@ packages:dependency: transitivedescription:name: platform- sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"+ sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65"url: "https://pub.dev"source: hosted- version: "3.1.4"+ version: "3.1.5"plugin_platform_interface:dependency: "direct dev"description:@@ -1941,10 +1941,10 @@ packages:dependency: transitivedescription:name: string_scanner- sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"+ sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"url: "https://pub.dev"source: hosted- version: "1.2.0"+ version: "1.3.0"string_validator:dependency: "direct main"description:@@ -2246,10 +2246,10 @@ packages:dependency: transitivedescription:name: vm_service- sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"+ sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"url: "https://pub.dev"source: hosted- version: "14.2.1"+ version: "14.2.5"watcher:dependency: transitivedescription:diff --git a/frontend/appflowy_flutter/test/unit_test/document/shortcuts/toggle_list_shortcut_test.dart b/frontend/appflowy_flutter/test/unit_test/document/shortcuts/toggle_list_shortcut_test.dartnew file mode 100644index 0000000000..d7c68f66aa--- /dev/null+++ b/frontend/appflowy_flutter/test/unit_test/document/shortcuts/toggle_list_shortcut_test.dart@@ -0,0 +1,53 @@+import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';+import 'package:appflowy_backend/log.dart';+import 'package:appflowy_editor/appflowy_editor.dart';+import 'package:flutter_test/flutter_test.dart';++void main() {+ group('toggle list shortcut:', () {+ Document createDocument(List<Node> nodes) {+ final document = Document.blank();+ document.insert([0], nodes);+ return document;+ }++ setUpAll(() {+ Log.shared.disableLog = true;+ });++ tearDownAll(() {+ Log.shared.disableLog = false;+ });++ testWidgets('> + #', (tester) async {+ const heading1 = '>Heading 1';+ const paragraph1 = 'paragraph 1';+ const paragraph2 = 'paragraph 2';++ final document = createDocument([+ headingNode(level: 1, text: heading1),+ paragraphNode(text: paragraph1),+ paragraphNode(text: paragraph2),+ ]);++ final editorState = EditorState(document: document);+ editorState.selection = Selection.collapsed(+ Position(path: [0], offset: 1),+ );++ final result = await formatGreaterToToggleList.execute(editorState);+ expect(result, true);++ expect(editorState.document.root.children.length, 1);+ final node = editorState.document.root.children[0];+ expect(node.type, ToggleListBlockKeys.type);+ expect(node.attributes[ToggleListBlockKeys.level], 1);+ expect(node.delta!.toPlainText(), 'Heading 1');+ expect(node.children.length, 2);+ expect(node.children[0].delta!.toPlainText(), paragraph1);+ expect(node.children[1].delta!.toPlainText(), paragraph2);++ editorState.dispose();+ });+ });+}diff --git a/frontend/appflowy_flutter/test/unit_test/document/turn_into/turn_into_test.dart b/frontend/appflowy_flutter/test/unit_test/document/turn_into/turn_into_test.dartindex 2cb78474ab..50e0462380 100644--- a/frontend/appflowy_flutter/test/unit_test/document/turn_into/turn_into_test.dart+++ b/frontend/appflowy_flutter/test/unit_test/document/turn_into/turn_into_test.dart@@ -19,6 +19,7 @@ void main() {String originalText, {Selection? selection,String? toType,+ int? level,void Function(EditorState editorState, Node node)? afterTurnInto,}) async {final editorState = EditorState(document: document);@@ -46,6 +47,7 @@ void main() {final result = await cubit.turnIntoBlock(type,node,+ level: level,);expect(result, true);final newNode = editorState.getNodeAtPath([0])!;@@ -683,5 +685,253 @@ void main() {Selection.collapsed(Position(path: [2])),);});++ group('turn into toggle list', () {+ const heading1 = 'heading 1';+ const heading2 = 'heading 2';+ const heading3 = 'heading 3';+ const paragraph1 = 'paragraph 1';+ const paragraph2 = 'paragraph 2';+ const paragraph3 = 'paragraph 3';++ test('turn heading 1 block to toggle heading 1 block', () async {+ // before+ // # Heading 1+ // paragraph 1+ // paragraph 2+ // paragraph 3++ // after+ // > # Heading 1+ // paragraph 1+ // paragraph 2+ // paragraph 3+ final document = createDocument([+ headingNode(level: 1, text: heading1),+ paragraphNode(text: paragraph1),+ paragraphNode(text: paragraph2),+ paragraphNode(text: paragraph3),+ ]);++ await checkTurnInto(+ document,+ HeadingBlockKeys.type,+ heading1,+ selection: Selection.collapsed(+ Position(path: [0]),+ ),+ toType: ToggleListBlockKeys.type,+ level: 1,+ afterTurnInto: (editorState, node) {+ expect(editorState.document.root.children.length, 1);+ expect(node.type, ToggleListBlockKeys.type);+ expect(node.attributes[ToggleListBlockKeys.level], 1);+ expect(node.children.length, 3);+ for (var i = 0; i < 3; i++) {+ expect(node.children[i].type, ParagraphBlockKeys.type);+ expect(+ node.children[i].delta!.toPlainText(),+ [paragraph1, paragraph2, paragraph3][i],+ );+ }++ // test undo together+ final result = undoCommand.execute(editorState);+ expect(result, KeyEventResult.handled);+ expect(editorState.document.root.children.length, 4);+ },+ );+ });++ test('turn toggle heading 1 block to heading 1 block', () async {+ // before+ // > # Heading 1+ // paragraph 1+ // paragraph 2+ // paragraph 3++ // after+ // # Heading 1+ // paragraph 1+ // paragraph 2+ // paragraph 3+ final document = createDocument([+ toggleHeadingNode(+ text: heading1,+ children: [+ paragraphNode(text: paragraph1),+ paragraphNode(text: paragraph2),+ paragraphNode(text: paragraph3),+ ],+ ),+ ]);++ await checkTurnInto(+ document,+ ToggleListBlockKeys.type,+ heading1,+ selection: Selection.collapsed(+ Position(path: [0]),+ ),+ toType: HeadingBlockKeys.type,+ level: 1,+ afterTurnInto: (editorState, node) {+ expect(editorState.document.root.children.length, 4);+ expect(node.type, HeadingBlockKeys.type);+ expect(node.attributes[HeadingBlockKeys.level], 1);+ expect(node.children.length, 0);+ for (var i = 1; i <= 3; i++) {+ final node = editorState.getNodeAtPath([i])!;+ expect(node.type, ParagraphBlockKeys.type);+ expect(+ node.delta!.toPlainText(),+ [paragraph1, paragraph2, paragraph3][i - 1],+ );+ }++ // test undo together+ editorState.selection = Selection.collapsed(+ Position(path: [0]),+ );+ final result = undoCommand.execute(editorState);+ expect(result, KeyEventResult.handled);+ expect(editorState.document.root.children.length, 1);+ final afterNode = editorState.getNodeAtPath([0])!;+ expect(afterNode.type, ToggleListBlockKeys.type);+ expect(afterNode.attributes[ToggleListBlockKeys.level], 1);+ expect(afterNode.children.length, 3);+ },+ );+ });++ test('turn heading 2 block to toggle heading 2 block - case 1', () async {+ // before+ // ## Heading 2+ // paragraph 1+ // ### Heading 3+ // paragraph 2+ // # Heading 1 <- the heading 1 block will not be converted+ // paragraph 3++ // after+ // > ## Heading 2+ // paragraph 1+ // ## Heading 2+ // paragraph 2+ // # Heading 1+ // paragraph 3+ final document = createDocument([+ headingNode(level: 2, text: heading2),+ paragraphNode(text: paragraph1),+ headingNode(level: 3, text: heading3),+ paragraphNode(text: paragraph2),+ headingNode(level: 1, text: heading1),+ paragraphNode(text: paragraph3),+ ]);++ await checkTurnInto(+ document,+ HeadingBlockKeys.type,+ heading2,+ selection: Selection.collapsed(+ Position(path: [0]),+ ),+ toType: ToggleListBlockKeys.type,+ level: 2,+ afterTurnInto: (editorState, node) {+ expect(editorState.document.root.children.length, 3);+ expect(node.type, ToggleListBlockKeys.type);+ expect(node.attributes[ToggleListBlockKeys.level], 2);+ expect(node.children.length, 3);+ expect(node.children[0].delta!.toPlainText(), paragraph1);+ expect(node.children[1].delta!.toPlainText(), heading3);+ expect(node.children[2].delta!.toPlainText(), paragraph2);++ // the heading 1 block will not be converted+ final heading1Node = editorState.getNodeAtPath([1])!;+ expect(heading1Node.type, HeadingBlockKeys.type);+ expect(heading1Node.attributes[HeadingBlockKeys.level], 1);+ expect(heading1Node.delta!.toPlainText(), heading1);++ final paragraph3Node = editorState.getNodeAtPath([2])!;+ expect(paragraph3Node.type, ParagraphBlockKeys.type);+ expect(paragraph3Node.delta!.toPlainText(), paragraph3);++ // test undo together+ final result = undoCommand.execute(editorState);+ expect(result, KeyEventResult.handled);+ expect(editorState.document.root.children.length, 6);+ },+ );+ });++ test('turn heading 2 block to toggle heading 2 block - case 2', () async {+ // before+ // ## Heading 2+ // paragraph 1+ // ## Heading 2 <- the heading 2 block will not be converted+ // paragraph 2+ // # Heading 1 <- the heading 1 block will not be converted+ // paragraph 3++ // after+ // > ## Heading 2+ // paragraph 1+ // ## Heading 2+ // paragraph 2+ // # Heading 1+ // paragraph 3+ final document = createDocument([+ headingNode(level: 2, text: heading2),+ paragraphNode(text: paragraph1),+ headingNode(level: 2, text: heading2),+ paragraphNode(text: paragraph2),+ headingNode(level: 1, text: heading1),+ paragraphNode(text: paragraph3),+ ]);++ await checkTurnInto(+ document,+ HeadingBlockKeys.type,+ heading2,+ selection: Selection.collapsed(+ Position(path: [0]),+ ),+ toType: ToggleListBlockKeys.type,+ level: 2,+ afterTurnInto: (editorState, node) {+ expect(editorState.document.root.children.length, 5);+ expect(node.type, ToggleListBlockKeys.type);+ expect(node.attributes[ToggleListBlockKeys.level], 2);+ expect(node.children.length, 1);+ expect(node.children[0].delta!.toPlainText(), paragraph1);++ final heading2Node = editorState.getNodeAtPath([1])!;+ expect(heading2Node.type, HeadingBlockKeys.type);+ expect(heading2Node.attributes[HeadingBlockKeys.level], 2);+ expect(heading2Node.delta!.toPlainText(), heading2);++ final paragraph2Node = editorState.getNodeAtPath([2])!;+ expect(paragraph2Node.type, ParagraphBlockKeys.type);+ expect(paragraph2Node.delta!.toPlainText(), paragraph2);++ // the heading 1 block will not be converted+ final heading1Node = editorState.getNodeAtPath([3])!;+ expect(heading1Node.type, HeadingBlockKeys.type);+ expect(heading1Node.attributes[HeadingBlockKeys.level], 1);+ expect(heading1Node.delta!.toPlainText(), heading1);++ final paragraph3Node = editorState.getNodeAtPath([4])!;+ expect(paragraph3Node.type, ParagraphBlockKeys.type);+ expect(paragraph3Node.delta!.toPlainText(), paragraph3);++ // test undo together+ final result = undoCommand.execute(editorState);+ expect(result, KeyEventResult.handled);+ expect(editorState.document.root.children.length, 6);+ },+ );+ });+ });});}diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.jsonindex 35c75c504f..5e1932526b 100644--- a/frontend/resources/translations/en.json+++ b/frontend/resources/translations/en.json@@ -1577,6 +1577,9 @@"mathEquation": "Math Equation","code": "Code","toggleList": "Toggle list",+ "toggleHeading1": "Toggle heading 1",+ "toggleHeading2": "Toggle heading 2",+ "toggleHeading3": "Toggle heading 3","emoji": "Emoji","aiWriter": "AI Writer","dateOrReminder": "Date or Reminder",