Skip to content

Commit 7f07498

Browse files
committed
feat(iOS): use system context menu in iOS(for secure paste)
1 parent 48f6b70 commit 7f07498

File tree

3 files changed

+477
-2
lines changed

3 files changed

+477
-2
lines changed

lib/src/editor/config/editor_config.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class QuillEditorConfig {
8686
this.readOnlyMouseCursor = SystemMouseCursors.text,
8787
this.onPerformAction,
8888
@experimental this.customLeadingBlockBuilder,
89+
this.useSystemContextMenuItems = false,
8990
});
9091

9192
@experimental
@@ -471,6 +472,11 @@ class QuillEditorConfig {
471472
/// Called when a text input action is performed.
472473
final void Function(TextInputAction action)? onPerformAction;
473474

475+
/// Show native context menu items on iOS.
476+
/// To use the default context menu items on iOS, set this to true.
477+
/// Use system context menu can unlock the secure paste feature for iOS
478+
final bool useSystemContextMenuItems;
479+
474480
// IMPORTANT For project authors: The copyWith()
475481
// should be manually updated each time we add or remove a property
476482

@@ -531,6 +537,7 @@ class QuillEditorConfig {
531537
void Function()? onScribbleActivated,
532538
EdgeInsets? scribbleAreaInsets,
533539
void Function(TextInputAction action)? onPerformAction,
540+
bool? useSystemContextMenuItems,
534541
}) {
535542
return QuillEditorConfig(
536543
customLeadingBlockBuilder:
@@ -600,6 +607,7 @@ class QuillEditorConfig {
600607
onScribbleActivated: onScribbleActivated ?? this.onScribbleActivated,
601608
scribbleAreaInsets: scribbleAreaInsets ?? this.scribbleAreaInsets,
602609
onPerformAction: onPerformAction ?? this.onPerformAction,
610+
useSystemContextMenuItems: useSystemContextMenuItems ?? this.useSystemContextMenuItems,
603611
);
604612
}
605613
}

lib/src/editor/editor.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import '../document/nodes/leaf.dart';
1818
import 'config/editor_config.dart';
1919
import 'embed/embed_editor_builder.dart';
2020
import 'raw_editor/config/raw_editor_config.dart';
21+
import 'raw_editor/quill_system_context_menu.dart';
2122
import 'raw_editor/raw_editor.dart';
2223
import 'widgets/box.dart';
2324
import 'widgets/cursor.dart';
@@ -281,8 +282,19 @@ class QuillEditorState extends State<QuillEditor>
281282
placeholder: config.placeholder,
282283
onLaunchUrl: config.onLaunchUrl,
283284
contextMenuBuilder: showSelectionToolbar
284-
? (config.contextMenuBuilder ??
285-
QuillRawEditorConfig.defaultContextMenuBuilder)
285+
? (config.useSystemContextMenuItems
286+
? (context, state) {
287+
if (QuillSystemContextMenu.isSupported(context)) {
288+
return QuillSystemContextMenu.quillEditor(
289+
quillEditorState: state,
290+
);
291+
}
292+
return (config.contextMenuBuilder ??
293+
QuillRawEditorConfig.defaultContextMenuBuilder)(
294+
context, state);
295+
}
296+
: (config.contextMenuBuilder ??
297+
QuillRawEditorConfig.defaultContextMenuBuilder))
286298
: null,
287299
showSelectionHandles: isMobile,
288300
showCursor: config.showCursor ?? true,

0 commit comments

Comments
 (0)