flutter-quill icon indicating copy to clipboard operation
flutter-quill copied to clipboard

Pasting from Microsoft Word raises Exceptions

Open lundmark opened this issue 9 months ago • 7 comments

Have you checked for an existing issue?

Flutter Quill Version

11.0.0

Steps to Reproduce

  1. Start the flutter quill test
  2. Open a document in Microsoft Word
  3. Copy a formatted section of text from Microsoft Word
  4. Paste into the flutter editor.
  5. Observe exception in default_clipboard_instance.dart line 19.

It seems like it's trying (and failing) to parse the html-version of the paste that's being sent. Microsoft Word also puts things in several different clipboards, among other the rich text which I think should be preferred in this way if the html-parser raises and exception.

Expected results

I'd expect the rich-text formatted text from word to be pasted into the Quill editor, appearing as

Actual results

Multiple exceptions and no text pasted into the Quill editor.

Additional Context

No response

lundmark avatar Mar 17 '25 20:03 lundmark

Are you testing on Windows? Could you please provide the error details including the stack trace?

EchoEllet avatar Mar 17 '25 22:03 EchoEllet

same problem, when paste from word in Windows (desktop app)

nano1209 avatar Mar 18 '25 14:03 nano1209

Hi!

Yes this is on windows.

Here is the callstack:

_Utf8Decoder.convertSingle (d:\work\flutter_sdk\flutter\bin\cache\pkg\sky_engine\lib\_internal\vm\lib\convert_patch.dart:1855) Utf8Decoder.convert (d:\work\flutter_sdk\flutter\bin\cache\pkg\sky_engine\lib\convert\utf.dart:351) Utf8Codec.decode (d:\work\flutter_sdk\flutter\bin\cache\pkg\sky_engine\lib\convert\utf.dart:64) Utf8Pointer.toDartString (c:\Users\simon\AppData\Local\Pub\Cache\hosted\pub.dev\ffi-2.1.3\lib\src\utf8.dart:48) QuillNativeBridgeWindows.getClipboardHtml (c:\Users\simon\AppData\Local\Pub\Cache\hosted\pub.dev\quill_native_bridge_windows-0.0.1\lib\quill_native_bridge_windows.dart:87) QuillNativeBridge.getClipboardHtml (c:\Users\simon\AppData\Local\Pub\Cache\hosted\pub.dev\quill_native_bridge-11.0.0\lib\quill_native_bridge.dart:64) DefaultClipboardService.getHtmlText (d:\work\code\flutter_quill\flutter-quill\lib\src\editor_toolbar_controller_shared\clipboard\default_clipboard_service.dart:19) <asynchronous gap> (Unknown Source:0) QuillControllerRichPaste.pasteHTML.getHTML (d:\work\code\flutter_quill\flutter-quill\lib\src\controller\clipboard\quill_controller_rich_paste.dart:25) <asynchronous gap> (Unknown Source:0) QuillControllerRichPaste.pasteHTML (d:\work\code\flutter_quill\flutter-quill\lib\src\controller\clipboard\quill_controller_rich_paste.dart:36) <asynchronous gap> (Unknown Source:0) QuillController.clipboardPaste (d:\work\code\flutter_quill\flutter-quill\lib\src\controller\quill_controller.dart:572) <asynchronous gap> (Unknown Source:0) QuillRawEditorState.pasteText (d:\work\code\flutter_quill\flutter-quill\lib\src\editor\raw_editor\raw_editor_state.dart:145) <asynchronous gap> (Unknown Source:0)

And the exception is: FormatException (FormatException: Unexpected extension byte (at offset 52848))

It is not a 100% bug and depends on what you paste in. When I try to paste in other stuff, like something easy, then the following can happen:

SourceURL:file:///<REDACTED DOCUMENT NAME>Here is some text I want to copy from word

Where "Here is some text I want to copy from word" was the text in the word document I copied.

lundmark avatar Mar 18 '25 14:03 lundmark

Could you try using the quill_super_clipboard implementation to see if this issue is reproducible?

Instructions

Add the dependency:

flutter pub add quill_super_clipboard

Then call QuillSuperClipboard.use:

import 'package:quill_super_clipboard/quill_super_clipboard.dart';

QuillSuperClipboard.use();

The issue might be with getClipboardHtml or html_formatter.dart or the HTML-to-delta parser.

Last time I tested on Windows 10 VM and didn't found any issues.

EchoEllet avatar Mar 18 '25 16:03 EchoEllet

This is the related line however we need to conform if this issue is reproducible with super_clipboard.

EchoEllet avatar Mar 22 '25 13:03 EchoEllet

Sorry, I haven't had the time to try it out with super clipboard yet. Will let you know as soon as I get some time to set it up.

lundmark avatar Mar 22 '25 16:03 lundmark

I am suspecting this is related.. When I past from Google Chrome into quill I am getting this error..

This is running in a Linux Desktop version of Chrome and pasting into Quill Running on a Linux Ubuntu workstation.

[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: Bad state: No element #0 List.last (dart:core-patch/growable_array.dart:357:5) #1 HtmlToDelta.nodeToOperation (package:flutter_quill_delta_from_html/parser/html_to_delta.dart:304:37) #2 HtmlToDelta.convert (package:flutter_quill_delta_from_html/parser/html_to_delta.dart:146:42) #3 DeltaX.fromHtml (package:flutter_quill/src/delta/delta_x.dart:46:24) #4 QuillControllerRichPaste.pasteHTML (package:flutter_quill/src/controller/clipboard/quill_controller_rich_paste.dart:40:37) #5 QuillController.clipboardPaste (package:flutter_quill/src/controller/quill_controller.dart:572:32) #6 QuillRawEditorState.pasteText (package:flutter_quill/src/editor/raw_editor/raw_editor_state.dart:145:9)

kedaly avatar Aug 04 '25 17:08 kedaly