Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jacobgoh101 opened this issue Apr 10, 2020 · 1 comment

Comments

@jacobgoh101
Copy link

jacobgoh101 commented Apr 10, 2020

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 ?
@jacobgoh101 jacobgoh101 changed the title result of .compose() contains delete Ops, which subsequently causes error diff() called with non-document result of ".compose()" contains "delete" Ops, which subsequently causes error "diff() called with non-document" Apr 10, 2020
@jhchen
Copy link
Member

jhchen commented Apr 10, 2020

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

@jhchen jhchen closed this as completed Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants