Skip to content

Commit

Permalink
Close pending unclosed groups when undo'ing.
Browse files Browse the repository at this point in the history
  • Loading branch information
graouts committed May 20, 2014
1 parent d8a37c1 commit 059e863
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ UndoManager.prototype = {
{
if (!this.canUndo)
return;


while (this._groupingLevel)
this.endGroup();

this._index--;

this._isUndoing = true;
Expand Down
17 changes: 17 additions & 0 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

</script>
Expand Down

0 comments on commit 059e863

Please sign in to comment.