smartxml: do not clear redo stack when performing nested transformation
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Sun, 8 Dec 2013 12:42:34 +0000 (13:42 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Sun, 15 Dec 2013 21:32:49 +0000 (22:32 +0100)
src/smartxml/smartxml.js
src/smartxml/smartxml.test.js

index 9c233bd..2fd4e41 100644 (file)
@@ -419,10 +419,10 @@ $.extend(Document.prototype, Backbone.Events, {
             if(this._transformationLevel === 1 && !this._undoInProgress) {
                 this.undoStack.push(transformation);
             }
             if(this._transformationLevel === 1 && !this._undoInProgress) {
                 this.undoStack.push(transformation);
             }
-            this._transformationLevel--;
-            if(!this._undoInProgress) {
+            if(!this._undoInProgress && this._transformationLevel === 1) {
                 this.redoStack = [];
             }
                 this.redoStack = [];
             }
+            this._transformationLevel--;
             return toret;
         } else {
             throw new Error('Transformation ' + transformation + ' doesn\'t exist!');
             return toret;
         } else {
             throw new Error('Transformation ' + transformation + ' doesn\'t exist!');
index 4049dff..90f7680 100644 (file)
@@ -1150,6 +1150,46 @@ describe('smartxml', function() {
             });
         });
 
             });
         });
 
+        it('smoke tests nested transformations', function() {
+            var doc = getDocumentFromXML('<div></div>');
+
+            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('<section><span>Alice</span></section>'),
         //         span = doc.root.contents()[0];
         // it('does work', function() {
         //     var doc = getDocumentFromXML('<section><span>Alice</span></section>'),
         //         span = doc.root.contents()[0];