From 87b31095331eab98415b37dbd2138cbd6a598b37 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Sun, 8 Dec 2013 13:42:34 +0100 Subject: [PATCH 1/1] smartxml: do not clear redo stack when performing nested transformation --- src/smartxml/smartxml.js | 4 ++-- src/smartxml/smartxml.test.js | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 9c233bd..2fd4e41 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -419,10 +419,10 @@ $.extend(Document.prototype, Backbone.Events, { if(this._transformationLevel === 1 && !this._undoInProgress) { this.undoStack.push(transformation); } - this._transformationLevel--; - if(!this._undoInProgress) { + if(!this._undoInProgress && this._transformationLevel === 1) { this.redoStack = []; } + this._transformationLevel--; return toret; } else { throw new Error('Transformation ' + transformation + ' doesn\'t exist!'); diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index 4049dff..90f7680 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -1150,6 +1150,46 @@ describe('smartxml', function() { }); }); + it('smoke tests nested transformations', function() { + var doc = getDocumentFromXML('
'); + + doc.registerExtension({elementNode: {transformations: { + nested: function(v) { + this._$.attr('innerAttr', v); + }, + outer: function(v) { + this.nested(v); + this._$.attr('outerAttr', v); + } + }}}); + + doc.root.outer('test1'); + doc.root.outer('test2'); + + expect(doc.root.getAttr('innerAttr')).to.equal('test2'); + expect(doc.root.getAttr('outerAttr')).to.equal('test2'); + + doc.undo(); + + expect(doc.root.getAttr('innerAttr')).to.equal('test1'); + expect(doc.root.getAttr('outerAttr')).to.equal('test1'); + + doc.undo(); + + expect(doc.root.getAttr('innerAttr')).to.equal(undefined); + expect(doc.root.getAttr('outerAttr')).to.equal(undefined); + + doc.redo(); + + expect(doc.root.getAttr('innerAttr')).to.equal('test1'); + expect(doc.root.getAttr('outerAttr')).to.equal('test1'); + + doc.redo(); + + expect(doc.root.getAttr('innerAttr')).to.equal('test2'); + expect(doc.root.getAttr('outerAttr')).to.equal('test2'); + + }); // it('does work', function() { // var doc = getDocumentFromXML('
Alice
'), // span = doc.root.contents()[0]; -- 2.20.1