slab/delta

result of ".compose()" contains "delete" Ops, which subsequently causes error "diff() called with non-document"

Closed this issue · 1 comments

Many thanks for this library.

I am facing this error diff() called with non-document.

After some digging, I realized that the error is thrown from this line from quill-delta https://github.com/quilljs/delta/blob/06ca777f67905ea6533272b2f88189ee06bb4197/src/Delta.ts#L278

If I understand correctly, for diff to work, a document has to contain ONLY insert Op.

But the result of .compose() contains delete Op.

You may run this simple Node code to reproduce the problem.

const Delta = require("quill-delta");

const oldContent = new Delta([
  {
    insert:
      "Well, you see... I'm buying this hotel and setting some new rules about the pool area. Well, you see... I'm buying this hotel and setting some new rules about the pool area. Bruce Wayne, eccentric billionaire.  ",
  },
  {
    insert: {
      citation: {
        citationId: "2066",
        label: "1",
      },
    },
  },
  {
    insert: "\n",
  },
]);

// This was generated from delta.diff(anotherDelta)
const diff = new Delta([
  {
    delete: 13,
  },
  {
    retain: 2,
    attributes: {
      color: null,
    },
  },
  {
    delete: 27,
  },
  {
    retain: 1,
    attributes: {
      color: null,
    },
  },
  {
    delete: 1,
  },
  {
    retain: 1,
    attributes: {
      color: null,
    },
  },
  {
    delete: 4,
  },
  {
    retain: 1,
    attributes: {
      color: null,
    },
  },
  {
    delete: 25,
  },
  {
    retain: 1,
    attributes: {
      color: null,
    },
  },
  {
    insert: {
      citation: {
        citationId: "2063",
        label: "1",
      },
    },
  },
  {
    delete: 484,
  },
]);

const newContent = oldContent.compose(diff);

console.log(newContent);
// result:
// [ { insert: '.. eg ' }, { insert: [Object] }, { delete: 347 } ] }

newContent.diff(new Delta());
// getting error `diff() called with non-document`
// because the `compose` result contains `delete`
  • is it a bug that .compose() returns delete Op?
  • how can I use diff() without getting the error diff() called with non-document ?

is it a bug that .compose() returns delete Op?

No. What its doing is correct and it is beyond the scope of this project to document how/why as these are operational transform concepts