-
Notifications
You must be signed in to change notification settings - Fork 993
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Have you checked for an existing issue?
- I have searched the existing issues
Flutter Quill Version
11.4.2
Steps to Reproduce
- On Windows, open Microsoft Word and copy the formatted text.
- Focus a QuillEditor and paste (Ctrl+V).
Expected results
Text should be pasted with formatting.
Actual results
For the same Word content the behavior is inconsistent:
- Sometimes formatted text is pasted correctly.
- Other times nothing is inserted and the following error is logged to the console.
Additional Context
Screenshots / Video demonstration
Word text:
When paste work:
When don't work (with my workaround in onClipboardPaste):
Logs
[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: FormatException: Missing extension byte (at offset 46628)
#0 _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1859:7)
#1 Utf8Decoder.convert (dart:convert/utf.dart:350:37)
#2 Utf8Codec.decode (dart:convert/utf.dart:63:20)
#3 Utf8Pointer.toDartString (package:ffi/src/utf8.dart:48:17)
#4 QuillNativeBridgeWindows.getClipboardHtml (package:quill_native_bridge_windows/quill_native_bridge_windows.dart:87:44)
#5 QuillNativeBridge.getClipboardHtml (package:quill_native_bridge/quill_native_bridge.dart:64:51)
#6 DefaultClipboardService.getHtmlText (package:flutter_quill/src/editor_toolbar_controller_shared/clipboard/default_clipboard_service.dart:19:47)
<asynchronous suspension>
#7 QuillControllerRichPaste.pasteHTML.getHTML (package:flutter_quill/src/controller/clipboard/quill_controller_rich_paste.dart:25:33)
<asynchronous suspension>
#8 QuillControllerRichPaste.pasteHTML (package:flutter_quill/src/controller/clipboard/quill_controller_rich_paste.dart:36:22)
<asynchronous suspension>
#9 QuillController.clipboardPaste (package:flutter_quill/src/controller/quill_controller.dart:572:32)
<asynchronous suspension>
#10 QuillRawEditorState.pasteText (package:flutter_quill/src/editor/raw_editor/raw_editor_state.dart:145:9)
<asynchronous suspension>Workarounds
- Disable external rich paste:
QuillControllerConfig(
clipboardConfig: QuillClipboardConfig(enableExternalRichPaste: false),
)
- Catch the FormatException and fallback to plain text (example used in my app):
QuillClipboardConfig(
onClipboardPaste: () async {
try {
final html = await QuillNativeBridge().getClipboardHtml();
if (html != null && html.trim().isNotEmpty) return false;
return false;
} on FormatException catch (e, st) {
// log and fallback to plain text
final data = await Clipboard.getData(Clipboard.kTextPlain);
final plain = data?.text ?? '';
if (plain.isEmpty) return true;
final sel = controller.selection;
final index = sel.start.clamp(0, controller.document.length);
final replaceLen =
(sel.end - sel.start).clamp(0, controller.document.length - index);
controller.replaceText(
index,
replaceLen,
plain,
TextSelection.collapsed(offset: index + plain.length),
);
return true;
}
},
)
A .docx file that can be used for testing:
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working