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: insert date from slash menu (#3783)
Mathias Mogensene66087861bb1
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dartindex ed795ea658..fb5e89a7dc 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart@@ -2,6 +2,7 @@ import 'package:appflowy/plugins/document/application/doc_bloc.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/background_color/theme_background_color.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/i18n/editor_i18n.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/image/custom_image_block_component.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/slash_menu_items.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';import 'package:appflowy/plugins/document/presentation/editor_style.dart';import 'package:appflowy/plugins/inline_actions/handlers/date_reference.dart';@@ -517,6 +518,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {toggleListBlockItem,emojiMenuItem,autoGeneratorMenuItem,+ dateMenuItem,];}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/slash_menu_items.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/slash_menu_items.dartnew file mode 100644index 0000000000..c2e8bf0769--- /dev/null+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/slash_menu_items.dart@@ -0,0 +1,45 @@+import 'package:appflowy/generated/flowy_svgs.g.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_block.dart';+import 'package:appflowy_editor/appflowy_editor.dart';++SelectionMenuItem dateMenuItem = SelectionMenuItem(+ name: 'Insert Date',+ icon: (_, isSelected, style) => FlowySvg(+ FlowySvgs.date_s,+ color: isSelected+ ? style.selectionMenuItemSelectedIconColor+ : style.selectionMenuItemIconColor,+ ),+ keywords: ['insert date', 'date', 'time'],+ handler: (editorState, menuService, context) =>+ _insertDateReference(editorState),+);++Future<void> _insertDateReference(EditorState editorState) async {+ final selection = editorState.selection;+ if (selection == null || !selection.isCollapsed) {+ return;+ }++ final node = editorState.getNodeAtPath(selection.end.path);+ final delta = node?.delta;+ if (node == null || delta == null) {+ return;+ }++ final transaction = editorState.transaction+ ..replaceText(+ node,+ selection.start.offset,+ 0,+ '\$',+ attributes: {+ MentionBlockKeys.mention: {+ MentionBlockKeys.type: MentionType.date.name,+ MentionBlockKeys.date: DateTime.now().toIso8601String(),+ }+ },+ );++ await editorState.apply(transaction);+}