Skip to content

Commit

Permalink
feat: add the option to disable rich text paste feature, partial fix to
Browse files Browse the repository at this point in the history
  • Loading branch information
EchoEllet committed Nov 8, 2024
1 parent 79ccfe8 commit f36deec
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
18 changes: 10 additions & 8 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,11 @@ class HomePage extends StatefulWidget {
}

class _HomePageState extends State<HomePage> {
late final QuillController _controller;
final FocusNode _editorFocusNode = FocusNode();
final ScrollController _editorScrollController = ScrollController();

@override
void initState() {
super.initState();
_controller = QuillController.basic(config: QuillControllerConfig(
final QuillController _controller = () {
return QuillController.basic(
config: QuillControllerConfig(
clipboardConfig: QuillClipboardConfig(
enableRichPaste: true,
onImagePaste: (imageBytes) async {
if (kIsWeb) {
// Dart IO is unsupported on the web.
Expand All @@ -69,7 +65,13 @@ class _HomePageState extends State<HomePage> {
},
),
));
}();
final FocusNode _editorFocusNode = FocusNode();
final ScrollController _editorScrollController = ScrollController();

@override
void initState() {
super.initState();
// Load document
_controller.document = Document.fromJson(kQuillDefaultSample);
}
Expand Down
9 changes: 9 additions & 0 deletions lib/src/controller/clipboard/quill_clipboard_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class QuillClipboardConfig {
@experimental this.onGifPaste,
@experimental this.onDeltaPaste,
@experimental this.onPlainTextPaste,
@experimental this.enableRichPaste,
});

/// Callback to allow overriding the default clipboard paste handling.
Expand Down Expand Up @@ -76,4 +77,12 @@ class QuillClipboardConfig {
/// Return modified text to override the pasted content, or `null` to use the default.
@experimental
final Future<String?> Function(String plainText)? onPlainTextPaste;

/// Determines if rich text pasting is enabled.
///
/// Defaults to `true`.
///
/// See also: https://pub.dev/packages/flutter_quill#-rich-text-paste
@experimental
final bool? enableRichPaste;
}
21 changes: 12 additions & 9 deletions lib/src/controller/quill_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -565,16 +565,19 @@ class QuillController extends ChangeNotifier {
return true;
}

final pasteHtmlSuccess = await pasteHTML();
if (pasteHtmlSuccess) {
updateEditor?.call();
return true;
}
const enableRichPasteDefault = true;
if (clipboardConfig?.enableRichPaste ?? enableRichPasteDefault) {
final pasteHtmlSuccess = await pasteHTML();
if (pasteHtmlSuccess) {
updateEditor?.call();
return true;
}

final pasteMarkdownSuccess = await pasteMarkdown();
if (pasteMarkdownSuccess) {
updateEditor?.call();
return true;
final pasteMarkdownSuccess = await pasteMarkdown();
if (pasteMarkdownSuccess) {
updateEditor?.call();
return true;
}
}

// Snapshot the input before using `await`.
Expand Down

0 comments on commit f36deec

Please sign in to comment.