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

[Quill][Bug] - Delta merging happens when not desired. #2303

Closed
matthew-carroll opened this issue Sep 4, 2024 · 1 comment · Fixed by #2318
Closed

[Quill][Bug] - Delta merging happens when not desired. #2303

matthew-carroll opened this issue Sep 4, 2024 · 1 comment · Fixed by #2318

Comments

@matthew-carroll
Copy link
Contributor

We're seeing some cases where serializing separate DocumentNodes to deltas results in multiple nodes being merged into single deltas when they should be separate deltas.

The merging action happens at the delta level - the originating DocumentNodes are irrelevant.

Reproduction deltas

Start with a serialized delta:

{
  "insert": "This paragraph is above the styled one:\n"
}

Then add another delta by executing TextBlockDeltaSerializer.serialize(node, deltas), which produces an intermediate delta like the following:

{
  "insert": "This is a block styled paragraph.",
  "attributes": {
    "banner-color": "red"
  }
}

Due to the delta merge decision within TextBlockDeltaSerializer we end up with a final single delta:

{
  "insert": "This paragraph is above the styled one:\nThis is a block styled paragraph.",
  "attributes": {
    "banner-color": "red"
  }
}

What we want to end up with is:

{
  "insert": "This paragraph is above the styled one:\n"
},
{
  "insert": "This is a block styled paragraph.",
  "attributes": {
    "banner-color": "red"
  }
}
@matthew-carroll
Copy link
Contributor Author

I think this issue was wrong.

In the original description I said that the following was a bad merge:

{
  "insert": "This paragraph is above the styled one:\nThis is a block styled paragraph.",
  "attributes": {
    "banner-color": "red"
  }
}

I think this is actually a correct merge. If I remember correctly, Quill Deltas don't blindly apply attributes to all text in the insert. Instead, every newline creates a barrier, even when the newline is in the same Delta. Therefore, when this Delta is processed, the first line gets a paragraph, and no attributes are applied. Then, the second line gets a paragraph, and the attributes are applied to that second paragraph. This results in the desired output.

Closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant