Restore deleted entries in a map
This commit is contained in:
parent
dc3e99e6a1
commit
1674d3986d
@ -200,7 +200,7 @@ export const redoItem = (transaction, item, redoitems, itemsToDelete, ignoreRemo
|
|||||||
} else {
|
} else {
|
||||||
right = null
|
right = null
|
||||||
if (item.right && !ignoreRemoteMapChanges) {
|
if (item.right && !ignoreRemoteMapChanges) {
|
||||||
left = item
|
left = item.right
|
||||||
// Iterate right while right is in itemsToDelete
|
// 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.
|
// 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)) {
|
while (left !== null && left.right !== null && isDeleted(itemsToDelete, left.right.id)) {
|
||||||
|
@ -644,3 +644,43 @@ export const testSpecialDeletionCase = tc => {
|
|||||||
undoManager.undo()
|
undoManager.undo()
|
||||||
t.compareStrings(fragment.toString(), '<test a="1" b="2"></test>')
|
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' })
|
||||||
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user