feat: add custom context menu items for copy, cut, and paste commands

This commit is contained in:
Lucas.Xu
2023-08-24 19:25:05 +08:00
parent 1ba7224088
commit 255f30590f
8 changed files with 56 additions and 12 deletions

View File

@ -159,6 +159,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
// customize the shortcuts
characterShortcutEvents: characterShortcutEvents,
commandShortcutEvents: commandShortcutEvents,
contextMenuItems: customContextMenuItems,
header: widget.header,
footer: const VSpace(200),
);

View File

@ -0,0 +1,21 @@
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
final List<List<ContextMenuItem>> customContextMenuItems = [
[
ContextMenuItem(
name: LocaleKeys.document_plugins_contextMenu_copy.tr(),
onPressed: (editorState) => customCopyCommand.execute(editorState),
),
ContextMenuItem(
name: LocaleKeys.document_plugins_contextMenu_paste.tr(),
onPressed: (editorState) => customPasteCommand.execute(editorState),
),
ContextMenuItem(
name: LocaleKeys.document_plugins_contextMenu_cut.tr(),
onPressed: (editorState) => customCutCommand.execute(editorState),
),
],
];

View File

@ -17,15 +17,7 @@ extension PasteNodes on EditorState {
if (delta.isEmpty) {
transaction.insertNode(
selection.end.path.next,
insertedDelta == null
? node.copyWith(
type: node.type,
attributes: {
...node.attributes,
...insertedNode.attributes,
},
)
: insertedNode,
insertedNode,
);
transaction.deleteNode(node);
final path = calculatePath(selection.end.path, [insertedNode]);

View File

@ -3,6 +3,7 @@ export 'actions/option_action.dart';
export 'callout/callout_block_component.dart';
export 'code_block/code_block_component.dart';
export 'code_block/code_block_shortcut_event.dart';
export 'context_menu/custom_context_menu.dart';
export 'copy_and_paste/custom_copy_command.dart';
export 'copy_and_paste/custom_cut_command.dart';
export 'copy_and_paste/custom_paste_command.dart';