From: Aleksander Ɓukasz Date: Fri, 7 Feb 2014 09:11:41 +0000 (+0100) Subject: smartxml: fix - running custom undo was stopping node arguments refetching on redo X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/7779d776e9256c0cdb8a3290e3a1fb62b761ff13?hp=51b143ce745947ba7a0db2d8d7cf4b68f30c7078 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. --- 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); }