slab / delta

Simple and expressive JSON format for describing rich-text content and their changes
https://quilljs.com/docs/delta
BSD 3-Clause "New" or "Revised" License
914 stars 130 forks source link

Why does a QullJS delta appear out of order? #59

Closed shamoons closed 4 years ago

shamoons commented 4 years ago

The delta that's generated looks like:

{"ops":[{"retain":710},{"insert":" yesterday, and she says—”\n“The clinic?","attributes":{"prediction":"prediction"}},{"delete":28}]}

My code is:

      const delta = new Delta()
          .retain(documentData?.prediction?.currentPosition)
          .delete(previousPredictionText?.length || 0)
          .insert(predictionText, { prediction: 'prediction' })

    console.log('delta', JSON.stringify(delta))

      quillEditor.updateContents(delta)

It looks like I should first retain, then delete, then insert, but the generated delta seems to do it in a different order. What am I doing wrong?

Cross linked at https://stackoverflow.com/questions/63430548/why-does-a-qulljs-delta-appear-out-of-order if anyone wants magic internet points