From 6258ed501e5b751d108b46ce70530ca9776811eb Mon Sep 17 00:00:00 2001 From: Jack Bird Date: Tue, 18 Jul 2023 19:19:56 +0100 Subject: [PATCH] updated undo command to only track when a command changes the tree --- src/js/sandbox/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/js/sandbox/index.js b/src/js/sandbox/index.js index 15a323d7..8b8de6c9 100644 --- a/src/js/sandbox/index.js +++ b/src/js/sandbox/index.js @@ -67,7 +67,8 @@ var Sandbox = Backbone.View.extend({ initGitShim: function(options) { this.gitShim = new GitShim({ - beforeCB: this.beforeCommandCB.bind(this) + beforeCB: this.beforeCommandCB.bind(this), + afterCB: this.afterCommandCB.bind(this) }); }, @@ -113,12 +114,21 @@ var Sandbox = Backbone.View.extend({ }, beforeCommandCB: function(command) { + this._treeBeforeCommand = this.mainVis.gitEngine.printTree(); + }, + + afterCommandCB: function(command) { this.pushUndo(); }, pushUndo: function() { + let currentTree = this.mainVis.gitEngine.printTree(); + if(currentTree === this._treeBeforeCommand) { + return; + } + // go ahead and push the three onto the stack - this.undoStack.push(this.mainVis.gitEngine.printTree()); + this.undoStack.push(this._treeBeforeCommand); }, undo: function(command, deferred) {