Restore deleted entries in a map

This commit is contained in:
Dominik Henneke 2023-03-28 20:32:22 +02:00 committed by Kevin Jahns
parent dc3e99e6a1
commit 1674d3986d
2 changed files with 41 additions and 1 deletions

View File

@ -200,7 +200,7 @@ export const redoItem = (transaction, item, redoitems, itemsToDelete, ignoreRemo
} else {
right = null
if (item.right && !ignoreRemoteMapChanges) {
left = item
left = item.right
// Iterate right while right is in itemsToDelete
// If it is intended to delete right while item is redone, we can expect that item should replace right.
while (left !== null && left.right !== null && isDeleted(itemsToDelete, left.right.id)) {

View File

@ -644,3 +644,43 @@ export const testSpecialDeletionCase = tc => {
undoManager.undo()
t.compareStrings(fragment.toString(), '<test a="1" b="2"></test>')
}
/**
* Deleted entries in a map should be restored on undo.
*
* @see https://github.com/yjs/yjs/issues/500
* @param {t.TestCase} tc
*/
export const testUndoDeleteInMap = (tc) => {
const { map0 } = init(tc, { users: 3 })
const undoManager = new Y.UndoManager(map0, { captureTimeout: 0 })
map0.set('a', 'a')
map0.delete('a')
map0.set('a', 'b')
map0.delete('a')
map0.set('a', 'c')
map0.delete('a')
map0.set('a', 'd')
t.compare(map0.toJSON(), { a: 'd' })
undoManager.undo()
t.compare(map0.toJSON(), {})
undoManager.undo()
t.compare(map0.toJSON(), { a: 'c' })
undoManager.undo()
t.compare(map0.toJSON(), {})
undoManager.undo()
t.compare(map0.toJSON(), { a: 'b' })
undoManager.undo()
t.compare(map0.toJSON(), {})
undoManager.undo()
t.compare(map0.toJSON(), { a: 'a' })
};