Skip to content

Commit

Permalink
Fix safari clipboard bug (singerdmx#1722)
Browse files Browse the repository at this point in the history
* on web platforms, do not call clipboard status update as security measures block that and currently cause safari to display a paste menu

* change default for web to pasteable
  • Loading branch information
mtallenca committed Feb 6, 2024
1 parent 5d9dc10 commit be84f1c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/src/widgets/others/text_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ class EditorTextSelectionOverlay {
// our listener being created
// we won't know the status unless there is forced update
// i.e. occasionally no paste
if (clipboardStatus != null) {
if (clipboardStatus != null && !kIsWeb) {
// Web - esp Safari Mac/iOS has security measures in place that restrict
// cliboard status checks w/o direct user interaction. So skip this
// for web
clipboardStatus!.update();
}
}
Expand Down
10 changes: 8 additions & 2 deletions lib/src/widgets/raw_editor/raw_editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'dart:math' as math;
import 'dart:ui' as ui hide TextStyle;

import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart' show defaultTargetPlatform;
import 'package:flutter/foundation.dart' show defaultTargetPlatform, kIsWeb;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart' show RenderAbstractViewport;
import 'package:flutter/scheduler.dart' show SchedulerBinding;
Expand Down Expand Up @@ -524,7 +524,13 @@ class QuillRawEditorState extends EditorState
);

if (!widget.configurations.disableClipboard) {
_clipboardStatus = ClipboardStatusNotifier();
// Web - esp Safari Mac/iOS has security measures in place that restrict
// cliboard status checks w/o direct user interaction. Initializing the
// ClipboardStatusNotifier with a default value of unknown will cause the
// clipboard status to be checked w/o user interaction which fails. Default
// to pasteable for web.
_clipboardStatus = ClipboardStatusNotifier(
value: kIsWeb ? ClipboardStatus.pasteable : ClipboardStatus.unknown);
}

if (widget.configurations.scrollable) {
Expand Down

0 comments on commit be84f1c

Please sign in to comment.