From: Aleksander Ɓukasz Date: Fri, 29 Nov 2013 10:27:19 +0000 (+0100) Subject: canvas: Fixing nodeMoved event handling X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/f2a4c98c8681e58fb9ee794129ce66ec0b06f0be?ds=sidebyside;hp=e1bff45c85b21d5d87640273319c9a8fd2377f86 canvas: Fixing nodeMoved event handling --- diff --git a/src/editor/modules/documentCanvas/canvas/canvas.test.js b/src/editor/modules/documentCanvas/canvas/canvas.test.js index 98b7ffe..ceccda3 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.test.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.test.js @@ -60,6 +60,33 @@ describe('Handling changes to the document', function() { }); }); +describe('Listening to document changes', function() { + it('Handling element node moved', function() { + var doc = getDocumentFromXML('
'), + a = doc.root.contents()[0], + b = doc.root.contents()[1], + c = canvas.fromXMLDocument(doc); + + a.before(b); + var sectionChildren = c.doc().children(); + expect(sectionChildren.length).to.equal(2); + expect(sectionChildren[0].getWlxmlTag()).to.equal('b'); + expect(sectionChildren[1].getWlxmlTag()).to.equal('a'); + }); + it('Handling text node moved', function() { + var doc = getDocumentFromXML('
Alice
'), + a = doc.root.contents()[0], + textNode = doc.root.contents()[1], + c = canvas.fromXMLDocument(doc); + + a.before(textNode); + var sectionChildren = c.doc().children(); + expect(sectionChildren.length).to.equal(2); + expect(sectionChildren[0].getText()).to.equal('Alice'); + expect(sectionChildren[1].getWlxmlTag()).to.equal('a'); + }); +}); + describe('Cursor', function() { var getSelection; diff --git a/src/editor/modules/documentCanvas/canvas/wlxmlListener.js b/src/editor/modules/documentCanvas/canvas/wlxmlListener.js index 2dd61ff..c5deabf 100644 --- a/src/editor/modules/documentCanvas/canvas/wlxmlListener.js +++ b/src/editor/modules/documentCanvas/canvas/wlxmlListener.js @@ -47,7 +47,7 @@ var handlers = { } var parentElement = utils.findCanvasElement(event.meta.node.parent()), nodeIndex = event.meta.node.getIndex(), - referenceElement, referenceAction; + referenceElement, referenceAction, actionArg; if(nodeIndex === 0) { referenceElement = parentElement; @@ -57,7 +57,8 @@ var handlers = { referenceAction = 'after'; } - referenceElement[referenceAction](event.meta.node); + actionArg = utils.findCanvasElement(event.meta.node) || event.meta.node; + referenceElement[referenceAction](actionArg); }, nodeMoved: function(event) { return handlers.nodeAdded(event);