Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/src/editor/config/editor_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class QuillEditorConfig {
this.readOnlyMouseCursor = SystemMouseCursors.text,
this.onPerformAction,
@experimental this.customLeadingBlockBuilder,
this.useSystemContextMenuItems = false,
});

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

/// Show native context menu items on iOS.
/// To use the default context menu items on iOS, set this to true.
/// Use system context menu can unlock the secure paste feature for iOS
final bool useSystemContextMenuItems;

// IMPORTANT For project authors: The copyWith()
// should be manually updated each time we add or remove a property

Expand Down Expand Up @@ -531,6 +537,7 @@ class QuillEditorConfig {
void Function()? onScribbleActivated,
EdgeInsets? scribbleAreaInsets,
void Function(TextInputAction action)? onPerformAction,
bool? useSystemContextMenuItems,
}) {
return QuillEditorConfig(
customLeadingBlockBuilder:
Expand Down Expand Up @@ -600,6 +607,7 @@ class QuillEditorConfig {
onScribbleActivated: onScribbleActivated ?? this.onScribbleActivated,
scribbleAreaInsets: scribbleAreaInsets ?? this.scribbleAreaInsets,
onPerformAction: onPerformAction ?? this.onPerformAction,
useSystemContextMenuItems: useSystemContextMenuItems ?? this.useSystemContextMenuItems,
);
}
}
29 changes: 25 additions & 4 deletions lib/src/editor/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import '../document/nodes/leaf.dart';
import 'config/editor_config.dart';
import 'embed/embed_editor_builder.dart';
import 'raw_editor/config/raw_editor_config.dart';
import 'raw_editor/quill_system_context_menu.dart';
import 'raw_editor/raw_editor.dart';
import 'widgets/box.dart';
import 'widgets/cursor.dart';
Expand Down Expand Up @@ -223,6 +224,29 @@ class QuillEditorState extends State<QuillEditor>
});
}

/// 构建上下文菜单构建器,简化嵌套逻辑
QuillEditorContextMenuBuilder? _buildContextMenuBuilder(bool showSelectionToolbar) {
if (!showSelectionToolbar) {
return null;
}

if (config.useSystemContextMenuItems) {
return (context, state) {
if (QuillSystemContextMenu.isSupported(context)) {
return QuillSystemContextMenu.quillEditor(
quillEditorState: state,
);
}
return (config.contextMenuBuilder ??
QuillRawEditorConfig.defaultContextMenuBuilder)(
context, state);
};
}

return config.contextMenuBuilder ??
QuillRawEditorConfig.defaultContextMenuBuilder;
}

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
Expand Down Expand Up @@ -280,10 +304,7 @@ class QuillEditorState extends State<QuillEditor>
disableClipboard: config.disableClipboard,
placeholder: config.placeholder,
onLaunchUrl: config.onLaunchUrl,
contextMenuBuilder: showSelectionToolbar
? (config.contextMenuBuilder ??
QuillRawEditorConfig.defaultContextMenuBuilder)
: null,
contextMenuBuilder: _buildContextMenuBuilder(showSelectionToolbar),
showSelectionHandles: isMobile,
showCursor: config.showCursor ?? true,
cursorStyle: CursorStyle(
Expand Down
Loading