mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: insert date from slash menu (#3783)
This commit is contained in:
parent
147637fcf5
commit
e66087861b
@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user