diff --git a/index.js b/index.js index fa009d1..64b9d63 100644 --- a/index.js +++ b/index.js @@ -32,7 +32,10 @@ UndoManager.prototype = { { if (!this.canUndo) return; - + + while (this._groupingLevel) + this.endGroup(); + this._index--; this._isUndoing = true; diff --git a/test.html b/test.html index 844672f..0c90950 100644 --- a/test.html +++ b/test.html @@ -148,6 +148,23 @@ console.log("Redo once"); manager.redo(); test("obj.foo === 20", obj.foo === 20); + + console.log("Increment obj.foo 4 times within two unclosed nested groups"); + manager.beginGroup(); + increment(2); + manager.beginGroup(); + increment(2); + test("obj.foo === 24", obj.foo === 24); + + console.log("Undo twice"); + manager.undo(); + manager.undo(); + test("obj.foo === 2", obj.foo === 2); + + console.log("Redo twice"); + manager.redo(); + manager.redo(); + test("obj.foo === 24", obj.foo === 24); });