From 7779d776e9256c0cdb8a3290e3a1fb62b761ff13 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 7 Feb 2014 10:11:41 +0100 Subject: [PATCH] smartxml: fix - running custom undo was stopping node arguments refetching on redo Custom undo function is getting transformation.context as its running context. Incrementing runCounter makes sure this node argument (and possible others used in undo) will be refetched via getPath on the next redo. Until now this was happening only for transformations without its own undo, which caused problems e.g. if redo was preceded by unaware transformation undo. --- src/smartxml/smartxml.test.js | 28 ++++++++++++++++++++++++++++ src/smartxml/transformations.js | 1 + 2 files changed, 29 insertions(+) diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index cbef963..7b42580 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -1592,6 +1592,34 @@ describe('smartxml', function() { expect(doc.root.getAttr('unaware')).to.equal('1'); }); }); + + describe('Regression tests', function() { + it('redos correctly after running its own undo followed by unaware transformation undo', function() { + var doc = getDocumentFromXML('
'); + + doc.registerExtension({elementNode: {transformations: { + unaware: function() { + this.triggerChangeEvent(); + }, + test: { + impl: function() { + this._$.attr('t', 1); + this.triggerChangeEvent(); + }, + undo: function() { + this._$.attr('t', 0); + } + } + }}}); + doc.root.unaware(); + doc.root.test(); + doc.undo(); + doc.undo(); + doc.redo(); + doc.redo(); + expect(doc.root.getAttr('t')).to.equal('1'); + }); + }); }); }); diff --git a/src/smartxml/transformations.js b/src/smartxml/transformations.js index a2a9f48..4a8e5a8 100644 --- a/src/smartxml/transformations.js +++ b/src/smartxml/transformations.js @@ -79,6 +79,7 @@ toret.createGenericTransformation = function(desc, name) { undo: function() { if(desc.undo) { desc.undo.call(this.context, this); + this.runCount++; } else { this.document.getNodeByPath(this.changeRootPath).replaceWith(this.snapshot); } -- 2.20.1