mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: add custom context menu items for copy, cut, and paste commands
This commit is contained in:
@ -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),
|
||||
);
|
||||
|
@ -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),
|
||||
),
|
||||
],
|
||||
];
|
@ -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]);
|
||||
|
@ -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';
|
||||
|
Reference in New Issue
Block a user