WIP WYSIWYG ~3D SVG editor.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement History and Command classes. Unused by Zoodle as of this commit.

+52 -1
+52 -1
zoodle.js
··· 27 27 }); 28 28 29 29 this.selection = []; 30 - this.queue = []; 30 + this.history = new History(); 31 31 this.tool = "orbit"; 32 32 this.tools = { 33 33 orbit: new OrbitTool(this), ··· 199 199 } 200 200 move(ptr, target, x, y) { 201 201 this.editor.fetch.rotateMove(ptr, target, x, y); 202 + } 203 + } 204 + 205 + class Command { 206 + constructor(editor) { 207 + this.editor = editor; 208 + } 209 + execute() {} 210 + undo() {} 211 + canMerge(command) { 212 + return false; 213 + } 214 + merge(command) {} 215 + } 216 + 217 + class History { 218 + constructor() { 219 + this.undoStack = []; 220 + this.redoStack = []; 221 + } 222 + 223 + push(command) { 224 + // Check to see if this command is mergeable into the last. 225 + let lastCommand = this.undoStack[this.undoStack.length - 1]; 226 + if (lastCommand.canMerge(command)) { 227 + lastCommand.merge(command); 228 + return; 229 + } 230 + 231 + this.undoStack.push(command); 232 + this.redoStack = []; 233 + } 234 + 235 + undo() { 236 + if (this.undoStack.length === 0) { 237 + return; 238 + } 239 + 240 + let command = this.undoStack.pop(); 241 + command.undo(); 242 + this.redoStack.push(command); 243 + } 244 + 245 + redo() { 246 + if (this.redoStack.length === 0) { 247 + return; 248 + } 249 + 250 + let command = this.redoStack.pop(); 251 + command.execute(); 252 + this.undoStack.push(command); 202 253 } 203 254 } 204 255