smartxml: fix - do not clear redo stack if we are just performing undo operation
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Sat, 7 Dec 2013 21:34:12 +0000 (22:34 +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 d722c20..eb97ea9 100644 (file)
@@ -436,7 +436,9 @@ $.extend(Document.prototype, Backbone.Events, {
             }
             this._transformationLevel--;
             //console.log('clearing redo stack');
-            this.redoStack = [];
+            if(!this._undoInProgress) {
+                this.redoStack = [];
+            }
             return toret;
         } else {
             throw new Error('Transformation ' + transformation + ' doesn\'t exist!');
index 3ee2793..991f1af 100644 (file)
@@ -1023,7 +1023,41 @@ describe('smartxml', function() {
             doc.undo();
             expect(doc.undoStack).to.have.length(0, '5');
             expect(doc.toXML()).to.equal('<div>Alice</div>');
+        });
+
+        it('smoke tests 2', function() {
+            var doc = getDocumentFromXML('<div>Alice</div>'),
+                textNode = doc.root.contents()[0],
+                path = textNode.getPath(),
+                result;
+
+            debugger;
+            textNode.setText('Alice ');
+            textNode.setText('Alice h');
+            textNode.setText('Alice ha');
+            textNode.setText('Alice has');
+
+            expect(textNode.getText()).to.equal('Alice has');
+
+            doc.undo();
+            expect(doc.root.contents()[0].getText()).to.equal('Alice ha', '1');
 
+            doc.undo();
+            expect(doc.root.contents()[0].getText()).to.equal('Alice h', '2');
+
+            doc.redo();
+            expect(doc.root.contents()[0].getText()).to.equal('Alice ha', '3');
+
+            doc.redo();
+            expect(doc.root.contents()[0].getText()).to.equal('Alice has', '4');
+
+            doc.undo();
+            doc.undo();
+            textNode = doc.getNodeByPath(path);
+            textNode.setText('Cat');
+            doc.undo();
+            textNode = doc.getNodeByPath(path);
+            expect(textNode.getText()).to.equal('Alice h');
         });
 
         // it('does work', function() {