From: Aleksander Ɓukasz Date: Fri, 9 May 2014 12:44:03 +0000 (+0200) Subject: editor: canvas fix X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/b18fdf0bf367567d1171c14438c03ac39fad3f6b?ds=sidebyside;hp=-c editor: canvas fix 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. --- b18fdf0bf367567d1171c14438c03ac39fad3f6b diff --git a/src/editor/modules/documentCanvas/canvas/canvas.test.js b/src/editor/modules/documentCanvas/canvas/canvas.test.js index 492292c..0654170 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.test.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.test.js @@ -208,16 +208,24 @@ describe('Default document changes handling', function() { }); it('handles moved node', function() { - var doc = getDocumentFromXML('
'), - a = doc.root.contents()[0], - b = doc.root.contents()[1], - c = canvas.fromXMLDocument(doc); + var doc = getDocumentFromXML('
'), + 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() { diff --git a/src/editor/modules/documentCanvas/canvas/documentElement.js b/src/editor/modules/documentCanvas/canvas/documentElement.js index e374a86..45592ef 100644 --- a/src/editor/modules/documentCanvas/canvas/documentElement.js +++ b/src/editor/modules/documentCanvas/canvas/documentElement.js @@ -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) {