Skip to content

Feat: disableClipboard option #1719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 6, 2024
Merged
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
11 changes: 11 additions & 0 deletions lib/src/models/config/editor/editor_configurations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class QuillEditorConfigurations extends Equatable {
this.expands = false,
this.placeholder,
this.readOnly = false,
this.disableClipboard = false,
this.textSelectionThemeData,
this.showCursor,
this.paintCursorAboveText,
Expand Down Expand Up @@ -92,6 +93,14 @@ class QuillEditorConfigurations extends Equatable {
/// Defaults to `false`. Must not be `null`.
final bool readOnly;

/// Disable Clipboard features
///
/// when this is set to `true` clipboard can not be used
/// this disables the clipboard notification for requesting permissions
///
/// Defaults to `false`. Must not be `null`.
final bool disableClipboard;

/// Whether this editor should create a scrollable container for its content.
///
/// When set to `true` the editor's height can be controlled by [minHeight],
Expand Down Expand Up @@ -342,6 +351,7 @@ class QuillEditorConfigurations extends Equatable {
QuillController? controller,
String? placeholder,
bool? readOnly,
bool? disableClipboard,
bool? scrollable,
double? scrollBottomInset,
EdgeInsetsGeometry? padding,
Expand Down Expand Up @@ -389,6 +399,7 @@ class QuillEditorConfigurations extends Equatable {
controller: controller ?? this.controller,
placeholder: placeholder ?? this.placeholder,
readOnly: readOnly ?? this.readOnly,
disableClipboard: disableClipboard ?? this.disableClipboard,
scrollable: scrollable ?? this.scrollable,
scrollBottomInset: scrollBottomInset ?? this.scrollBottomInset,
padding: padding ?? this.padding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class QuillRawEditorConfigurations extends Equatable {
this.scrollable = true,
this.padding = EdgeInsets.zero,
this.readOnly = false,
this.disableClipboard = false,
this.placeholder,
this.onLaunchUrl,
this.contextMenuBuilder = defaultContextMenuBuilder,
Expand Down Expand Up @@ -99,6 +100,14 @@ class QuillRawEditorConfigurations extends Equatable {
/// Defaults to false. Must not be null.
final bool readOnly;

/// Disable Clipboard features
///
/// when this is set to true clipboard can not be used
/// this disables the clipboard notification for requesting permissions
///
/// Defaults to false. Must not be null.
final bool disableClipboard;

final String? placeholder;

/// Callback which is triggered when the user wants to open a URL from
Expand Down
1 change: 1 addition & 0 deletions lib/src/widgets/editor/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class QuillEditorState extends State<QuillEditor>
scrollBottomInset: configurations.scrollBottomInset,
padding: configurations.padding,
readOnly: configurations.readOnly,
disableClipboard: configurations.disableClipboard,
placeholder: configurations.placeholder,
onLaunchUrl: configurations.onLaunchUrl,
contextMenuBuilder: showSelectionToolbar
Expand Down
8 changes: 5 additions & 3 deletions lib/src/widgets/others/text_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class EditorTextSelectionOverlay {
required this.debugRequiredFor,
required this.selectionCtrls,
required this.selectionDelegate,
required this.clipboardStatus,
required this.contextMenuBuilder,
this.clipboardStatus,
this.onSelectionHandleTapped,
this.dragStartBehavior = DragStartBehavior.start,
this.handlesVisible = false,
Expand All @@ -82,7 +82,9 @@ class EditorTextSelectionOverlay {
// our listener being created
// we won't know the status unless there is forced update
// i.e. occasionally no paste
clipboardStatus.update();
if (clipboardStatus != null) {
clipboardStatus!.update();
}
}

TextEditingValue value;
Expand Down Expand Up @@ -167,7 +169,7 @@ class EditorTextSelectionOverlay {
///
/// Useful because the actual value of the clipboard can only be checked
/// asynchronously (see [Clipboard.getData]).
final ClipboardStatusNotifier clipboardStatus;
final ClipboardStatusNotifier? clipboardStatus;

/// A pair of handles. If this is non-null, there are always 2, though the
/// second is hidden when the selection is collapsed.
Expand Down
22 changes: 15 additions & 7 deletions lib/src/widgets/raw_editor/raw_editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class QuillRawEditorState extends EditorState
String get pastePlainText => _pastePlainText;
String _pastePlainText = '';

final ClipboardStatusNotifier _clipboardStatus = ClipboardStatusNotifier();
ClipboardStatusNotifier? _clipboardStatus;
final LayerLink _toolbarLayerLink = LayerLink();
final LayerLink _startHandleLayerLink = LayerLink();
final LayerLink _endHandleLayerLink = LayerLink();
Expand Down Expand Up @@ -319,7 +319,8 @@ class QuillRawEditorState extends EditorState
/// Copied from [EditableTextState].
List<ContextMenuButtonItem> get contextMenuButtonItems {
return EditableText.getEditableButtonItems(
clipboardStatus: _clipboardStatus.value,
clipboardStatus:
(_clipboardStatus != null) ? _clipboardStatus!.value : null,
onCopy: copyEnabled
? () => copySelection(SelectionChangedCause.toolbar)
: null,
Expand Down Expand Up @@ -522,6 +523,10 @@ class QuillRawEditorState extends EditorState
),
);

if (!widget.configurations.disableClipboard) {
_clipboardStatus = ClipboardStatusNotifier();
}

if (widget.configurations.scrollable) {
/// Since [SingleChildScrollView] does not implement
/// `computeDistanceToActualBaseline` it prevents the editor from
Expand Down Expand Up @@ -1116,8 +1121,9 @@ class QuillRawEditorState extends EditorState
@override
void initState() {
super.initState();

_clipboardStatus.addListener(_onChangedClipboardStatus);
if (_clipboardStatus != null) {
_clipboardStatus!.addListener(_onChangedClipboardStatus);
}

controller.addListener(_didChangeTextEditingValueListener);

Expand Down Expand Up @@ -1271,9 +1277,11 @@ class QuillRawEditorState extends EditorState
controller.removeListener(_didChangeTextEditingValueListener);
widget.configurations.focusNode.removeListener(_handleFocusChanged);
_cursorCont.dispose();
_clipboardStatus
..removeListener(_onChangedClipboardStatus)
..dispose();
if (_clipboardStatus != null) {
_clipboardStatus!
..removeListener(_onChangedClipboardStatus)
..dispose();
}
super.dispose();
}

Expand Down