smartxml: fix - running custom undo was stopping node arguments refetching on redo
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 7 Feb 2014 09:11:41 +0000 (10:11 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 7 Feb 2014 09:14:37 +0000 (10:14 +0100)
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.

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

index cbef963..7b42580 100644 (file)
@@ -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('<section t="0"></section>');
+                
+                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');
+            });
+        });
     });
 
 });
index a2a9f48..4a8e5a8 100644 (file)
@@ -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);
             }