editor: canvas fix
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 9 May 2014 12:44:03 +0000 (14:44 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 12 May 2014 08:52:00 +0000 (10:52 +0200)
Dropping canvas reference on detach whas ultimately never used
and not bringing it back on subsequent attachments is a bug, so just
keep it forever.

src/editor/modules/documentCanvas/canvas/canvas.test.js
src/editor/modules/documentCanvas/canvas/documentElement.js

index 492292c..0654170 100644 (file)
@@ -208,16 +208,24 @@ describe('Default document changes handling', function() {
     });
 
     it('handles moved node', function() {
-        var doc = getDocumentFromXML('<section><a></a><b></b></section>'),
-            a = doc.root.contents()[0],
-            b = doc.root.contents()[1],
-            c = canvas.fromXMLDocument(doc);
+        var doc = getDocumentFromXML('<section><c></c><a></a><b></b></section>'),
+            c = doc.root.contents()[0],
+            a = doc.root.contents()[1],
+            b = doc.root.contents()[2],
+            cv = canvas.fromXMLDocument(doc);
+
+        a.document.transaction(function() {
+            a.before(b); // => cab
+            b.after(c); // => bca
+        }, {
+            error: function(e) {throw e;}
+        });
 
-        a.before(b);
-        var sectionChildren = c.doc().children();
-        expect(sectionChildren.length).to.equal(2);
+        var sectionChildren = cv.doc().children();
+        expect(sectionChildren.length).to.equal(3);
         expect(sectionChildren[0].wlxmlNode.getTagName()).to.equal('b');
-        expect(sectionChildren[1].wlxmlNode.getTagName()).to.equal('a');
+        expect(sectionChildren[1].wlxmlNode.getTagName()).to.equal('c');
+        expect(sectionChildren[2].wlxmlNode.getTagName()).to.equal('a');
     });
 
     it('handles moving text node to another parent', function() {
index e374a86..45592ef 100644 (file)
@@ -112,7 +112,6 @@ $.extend(DocumentNodeElement.prototype, {
     detach: function() {
         var parents = this.parents();
         this.dom.detach();
-        this.canvas = null;
         if(parents[0]) {
             parents[0].refreshPath();
         }
@@ -188,7 +187,6 @@ $.extend(DocumentTextElement.prototype, {
     },
     detach: function() {
         this.dom.detach();
-        this.canvas = null;
         return this;
     },
     setText: function(text) {