From: Aleksander Ɓukasz Date: Sun, 8 Dec 2013 12:42:34 +0000 (+0100) Subject: smartxml: do not clear redo stack when performing nested transformation X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/87b31095331eab98415b37dbd2138cbd6a598b37?hp=6b6d2a8c7dfde855e81a9b02ca38f69d6dfb9440 smartxml: do not clear redo stack when performing nested transformation --- 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];