From 38125881369cb87c35eb6a7b7e24f7c0130a32bb Mon Sep 17 00:00:00 2001 From: Julie Lala Date: Tue, 12 Aug 2014 09:15:30 -0400 Subject: register undo types --- public/assets/javascripts/rectangles/util/undo.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'public/assets/javascripts/rectangles/util/undo.js') 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 } -- cgit v1.2.3-70-g09d2