diff options
| author | Julie Lala <jules@okfoc.us> | 2014-08-12 09:15:30 -0400 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2014-08-12 09:15:30 -0400 |
| commit | 38125881369cb87c35eb6a7b7e24f7c0130a32bb (patch) | |
| tree | 60353113645483e0b8537605ec9e32df488c14bd /public/assets/javascripts/rectangles/util | |
| parent | 9cd88d59e45b530e483490804503e6b47030fd4d (diff) | |
register undo types
Diffstat (limited to 'public/assets/javascripts/rectangles/util')
| -rw-r--r-- | public/assets/javascripts/rectangles/util/undo.js | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/public/assets/javascripts/rectangles/util/undo.js b/public/assets/javascripts/rectangles/util/undo.js index 3700817..5d8593c 100644 --- a/public/assets/javascripts/rectangles/util/undo.js +++ b/public/assets/javascripts/rectangles/util/undo.js @@ -17,7 +17,7 @@ UndoStack.prototype.undo = function(){ if (this.pointer == -1) return false var action = this.stack[this.pointer] - this.types[ action.type ].undo(action) + this.types[ action.type ].undo(action.prev) this.pointer-- return this.pointer > -1 } @@ -25,13 +25,20 @@ if (this.pointer == this.stack.length-1) return false this.pointer++ var action = this.stack[this.pointer] - this.types[ action.type ].redo(action) + this.types[ action.type ].redo(action.next) return this.pointer < this.stack.length-1 } UndoStack.prototype.register = function(actionType){ - this.types[ actionType.type ] = actionType + if (actionType.length) { + actionType.forEach(this.registerOne.bind(this)) + } + else { + this.registerOne(actionType) + } } - + UndoStack.prototype.registerOne = function(actionType){ + this.types[ actionType.type ] = actionType + } if ('window' in this) { window.UndoStack = new UndoStack } |
