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

Fix retains for embedded types in YTextEvent #530

Closed
wants to merge 4 commits into from

Conversation

ezeidman
Copy link

@ezeidman ezeidman commented May 3, 2023

Don't include attributes in retains for embedded types since they're not subject to formatting

This fixes #529

Huly®: YJS-578

@ezeidman ezeidman force-pushed the ezeidman/fix-embed-retain branch from e4ede11 to 63aafba Compare May 3, 2023 19:04
@ezeidman ezeidman force-pushed the ezeidman/fix-embed-retain branch from 080407b to e1fd2de Compare May 3, 2023 20:22
@ezeidman ezeidman marked this pull request as ready for review May 3, 2023 20:23
@dmonad
Copy link
Member

dmonad commented May 5, 2023

Thank you!
Can you please confirm that this is the same behavior as in https://github.com/quilljs/delta/ ?

@ezeidman
Copy link
Author

ezeidman commented May 5, 2023

Thank you! Can you please confirm that this is the same behavior as in https://github.com/quilljs/delta/ ?

Could you clarify what you mean? The deltas from both before and after the PR are valid Quill deltas. The issue however is that retains associated with embedded types (e.g. an XmlText inside an XmlText) can contain unrelated attribute updates that are actually associated with surrounding text. This could be an erroneous null attribute like the example in the linked ticket or an erroneous non-null attribute value.

An example:

  const doc =  new Y.Doc()
  const root = doc.get("text", Y.XmlText) as Y.XmlText;
  const p1 = new Y.XmlText();
  p1.setAttribute("type", "paragraph")
  p1.insert(0, "p1")
  
  root.insert(0, "abc", {bold: true});
  root.insert(3, "defghi", {bold: false});
  root.insertEmbed(6, p1);
  
  root.observeDeep((events) => {
    events.forEach(event => {
      console.log("Event", JSON.stringify(event.changes, null, 4));
    })
  })

  root.delete(3, 3);

produces
Screenshot 2023-05-05 at 2 28 00 PM

where the retain is applying bold=false to the XmlText even though it's not bold and neither are its contents.

There is one issue with this PR as is: it can create more retains than are strictly necessary. For example [retain 3, retain 4, retain 1], instead of just retain 8. That's still a valid Quill delta but not the most concise way to represent things.

@ezeidman ezeidman force-pushed the ezeidman/fix-embed-retain branch from b47a6d2 to bbbe4da Compare May 6, 2023 00:55
})
text0.delete(3, 3);
testConnector.flushAllMessages()
t.compare(deltas, [[{retain: 3}, { delete: 3}]])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the fix this is [[{"retain":3},{"delete":3},{"retain":4,"attributes":{"bold":false}}]]

})
text0.delete(0, 3);
testConnector.flushAllMessages()
t.compare(deltas, [[{ delete: 3}]])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the fix this is [[{"delete":3},{"retain":1,"attributes":{"bold":null}}]]

@ezeidman ezeidman closed this May 8, 2023
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

Successfully merging this pull request may close these issues.

Text deletion event includes erroneous retain attribute
2 participants