-
-
Notifications
You must be signed in to change notification settings - Fork 570
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
Undoing a deletion can fail to restore an attribute #534
Labels
Comments
hi, @gblaketx I change your code & the issue is not reproduce. const Y = require('yjs');
const localOrigin = 'localOrigin';
// 1. Set up a document containing an XmlText with a single attribute
const localYDoc = new Y.Doc();
const localSharedRoot = localYDoc.get("text", Y.XmlText);
const undoManager = new Y.UndoManager(localSharedRoot, { trackedOrigins: new Set([localOrigin]) });
const testEmbed = new Y.XmlElement();
testEmbed.setAttribute("type", "paragraph");
localSharedRoot.insertEmbed(0, testEmbed);
// 2. Set the embed attribute, then delete the embed
localYDoc.transact(() => {
testEmbed.setAttribute("type", "list-item");
// localSharedRoot.delete(0, 1);
}, localOrigin);
// 3. Set up a second yDoc to match the state of the first
const remoteYDoc = new Y.Doc();
remoteYDoc.get("text", Y.XmlText);
Y.applyUpdate(remoteYDoc, Y.encodeStateAsUpdate(localYDoc));
// 4. Apply the update to the second yDoc
localYDoc.on("update", (update) => {
Y.applyUpdate(remoteYDoc, update);
});
console.log('--- before undo ---', {
localYDoc: localYDoc.toJSON(),
remoteYDoc: remoteYDoc.toJSON()
});
// 5. Undo the change, tracking the update
undoManager.undo();
// 6. The two yDocs are not equal. The delete sets are different.
console.log('--- after undo ---', {
localYDoc: localYDoc.toJSON(),
remoteYDoc: remoteYDoc.toJSON()
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
If you set an attribute on an XmlText and delete the node in the same transaction, then undo the change, the resulting update does not restore the original attribute.
To Reproduce
Steps to reproduce the behavior:
In code:
Expected behavior
Expect the two docs to remain equal after applying the undo update to both of them.
Screenshots
The documents diverge, as can be seen by comparing their snapshots. (
received
is the remote doc,expected
is the local,)Environment Information
Additional context
Ran into the problem while using Slate Yjs and attempting to undo a list creation. Creating the list would change the type of the target element, then move it into a wrapper node, which resulted in remove and insert operations using the element. As a workaround, we've updated our list creation logic to avoid this particular order of operations.
The text was updated successfully, but these errors were encountered: