smartxml: transaction rollback fix
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 2 Apr 2014 19:22:47 +0000 (21:22 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 2 Apr 2014 19:23:05 +0000 (21:23 +0200)
Not resetting transformationLevel counter on rollback caused subsequent
top level transformations to not being pushed to undo stack which
broke undo in that scenario.

src/smartxml/smartxml.js
src/smartxml/smartxml.test.js

index c23e06d..7d3f332 100644 (file)
@@ -581,6 +581,7 @@ $.extend(Document.prototype, Backbone.Events, {
         this.replaceRoot(this._rollbackBackup);
         this._rollbackBackup = null;
         this._currentTransaction = null;
         this.replaceRoot(this._rollbackBackup);
         this._rollbackBackup = null;
         this._currentTransaction = null;
+        this._transformationLevel = 0;
     },
 
     transaction: function(callback, params) {
     },
 
     transaction: function(callback, params) {
index e4e2724..5d1ca3e 100644 (file)
@@ -1679,6 +1679,29 @@ describe('smartxml', function() {
                 doc.redo();
                 expect(doc.root.getAttr('t')).to.equal('1');
             });
                 doc.redo();
                 expect(doc.root.getAttr('t')).to.equal('1');
             });
+            it('can perform undo of an operation performed after automatic transaction rollback', function() {
+                var doc = getDocumentFromXML('<section></section>'),
+                    extension = {document: {transformations: {
+                        throwingTransformation: function() { throw new Error(); }
+                    }}};
+
+                doc.registerExtension(extension);
+
+                doc.throwingTransformation();
+
+                doc.transaction(function() {
+                    doc.root.setAttr('x', '2');
+                });
+
+                expect(doc.undoStack.length).to.equal(1);
+                expect(doc.root.getAttr('x')).to.equal('2');
+
+                doc.undo();
+
+                expect(doc.undoStack.length).to.equal(0);
+                expect(doc.root.getAttr('x')).to.be.undefined;
+
+            });
         });
     });
 
         });
     });