diff options
Diffstat (limited to 'public/assets/javascripts/rectangles/util/undo.js')
| -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 } |
