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

[Desktop] Loading delta to controller throws exception

Open mmasdivins opened this issue 2 years ago • 5 comments

Hello, I was trying to load a delta to the document. The delta is generated using node-quill-converter that converts an HTML to delta. I have two problems loading the delta generated. The first one: Failed assertion: line 357 pos 12: '(doc.last.data as String).endsWith('\n')': is not true.

It expects that the last operation of the delta is '\n' if I add it, it works fine, but I don't know why it have to end with a '\n' to work.

The second error: Failed assertion: line 30 pos 12: 'value.isInline || value.isIgnored || value.isEmpty': Unable to apply Style to leaf: {Attribute{key: list, scope: AttributeScope.BLOCK, value: ordered}, Attribute{key: color, scope: AttributeScope.INLINE, value: #800080}} On leaf.dart if I comment the lines on the applyStyle function:

  @override
  void applyStyle(Style value) {
    // assert(value.isInline || value.isIgnored || value.isEmpty,
    //     'Unable to apply Style to leaf: $value');
    super.applyStyle(value);
  }

Works fine and the document is loaded without a problem. It throws an error because the attribute scope is BLOCK, why does only assert if is INLINE?

Here is the delta that I was using:

{
   "ops":[
      {
         "attributes":{
            "italic":true,
            "color":"#800080"
         },
         "insert":"una ampliacióde prova"
      },
      {
         "insert":"\n·     "
      },
      {
         "attributes":{
            "italic":true,
            "color":"#800080"
         },
         "insert":"sense"
      },
      {
         "insert":"\n·     "
      },
      {
         "attributes":{
            "italic":true,
            "color":"#800080"
         },
         "insert":"ordre"
      },
      {
         "insert":"\n"
      },
      {
         "attributes":{
            "italic":true,
            "color":"#800080"
         },
         "insert":"aaa"
      },
      {
         "insert":"\n"
      },
      {
         "attributes":{
            "list":"ordered",
            "italic":true,
            "color":"#800080"
         },
         "insert":"llista numerada 1"
      },
      {
         "attributes":{
            "list":"ordered"
         },
         "insert":"\n"
      },
      {
         "attributes":{
            "list":"ordered",
            "italic":true,
            "color":"#800080"
         },
         "insert":"llista numerada 2"
      },
      {
         "attributes":{
            "list":"ordered"
         },
         "insert":"\n"
      },
      {
         "attributes":{
            "italic":true,
            "color":"#800080"
         },
         "insert":" "
      },
      {
         "insert":"\n"
      },
      {
         "attributes":{
            "link":"https://github.com/kenyog/rtf-to-quill-delta/blob/master/rtf-to-delta.js",
            "italic":true,
            "color":"#0000ff"
         },
         "insert":"un link"
      },
      {
         "insert":"\n"
      },
      {
         "attributes":{
            "italic":true,
            "color":"#800080"
         },
         "insert":"\n"
      }
   ]
}

Note that I added the last '\n'.

mmasdivins avatar Feb 23 '23 14:02 mmasdivins