Quill: throw error when I return a delta async in an addMatcher handler

Created on 28 Feb 2018  路  5Comments  路  Source: quilljs/quill

 this.quill.clipboard.addMatcher('img', function (node, delta) {
        let d = new Delta().insert('Hello', { bold: true })
            .insert({ image: 'https://octodex.github.com/images/labtocat.png' })
            .insert('World!')
          return d
      })

when I ran codes like above, It worked perfectly. BUT when I changed to something like:

     this.quill.clipboard.addMatcher('img', function (node, delta) {
        setTimeout(() => {
          let d = new Delta().insert('Hello', { bold: true })
            .insert({ image: 'https://octodex.github.com/images/labtocat.png' })
            .insert('World!')
          return d
        }, 1000)
      })

the process failed, and threw error like:

2018-02-28 3 30 02

Most helpful comment

You can update content after request

quill.updateContents(
    new Delta()
      .retain(quill.getSelection().index)
      .insert('Hello', { bold: true })
      .insert({ image: 'https://octodex.github.com/images/labtocat.png' })
      .insert('World!')
));

All 5 comments

because your handler returns undefined, your return inside setTimeout

@volser I need reset the delta after server's response. How could I solve the problem ?

You can update content after request

quill.updateContents(
    new Delta()
      .retain(quill.getSelection().index)
      .insert('Hello', { bold: true })
      .insert({ image: 'https://octodex.github.com/images/labtocat.png' })
      .insert('World!')
));

@volser thank you for answering the question.

You can update content after request

quill.updateContents(
    new Delta()
      .retain(quill.getSelection().index)
      .insert('Hello', { bold: true })
      .insert({ image: 'https://octodex.github.com/images/labtocat.png' })
      .insert('World!')
));

Amazing! this answer should be show on FAQ for quilljs documenation

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Softvision-MariusComan picture Softvision-MariusComan  路  3Comments

rsdrsd picture rsdrsd  路  3Comments

GildedHonour picture GildedHonour  路  3Comments

CHR15- picture CHR15-  路  3Comments

splacentino picture splacentino  路  3Comments