editor: canvas bug fix
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 12 May 2014 08:51:54 +0000 (10:51 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 12 May 2014 08:51:54 +0000 (10:51 +0200)
src/editor/modules/documentCanvas/canvas/canvas.test.js
src/editor/modules/documentCanvas/canvas/genericElement.js

index f64754f..492292c 100644 (file)
@@ -243,6 +243,19 @@ describe('Default document changes handling', function() {
         c.wlxmlDocument.root.contents()[0].setText('cat');
         expect(c.doc().children()[0].getText()).to.equal('cat');
     });
         c.wlxmlDocument.root.contents()[0].setText('cat');
         expect(c.doc().children()[0].getText()).to.equal('cat');
     });
+
+    describe('Regression tests', function() {
+        it('handles moving node after its next neighbour correctly', function() {
+            var c = getCanvasFromXML('<section><a></a><b></b></section>'),
+                doc = c.wlxmlDocument,
+                a = doc.root.contents()[0],
+                b = doc.root.contents()[1];
+            b.after(a);
+            var sectionChildren = c.doc().children();
+            expect(sectionChildren[0].wlxmlNode.getTagName()).to.equal('b');
+            expect(sectionChildren[1].wlxmlNode.getTagName()).to.equal('a');
+        });
+    });
 });
     
 describe('Custom elements based on wlxml class attribute', function() {
 });
     
 describe('Custom elements based on wlxml class attribute', function() {
index 4bdc524..a2601f8 100644 (file)
@@ -105,6 +105,9 @@ $.extend(generic, {
       
         if(event.type === 'nodeMoved') {
             actionArg = utils.getElementForNode(event.meta.node, event.meta.parent);
       
         if(event.type === 'nodeMoved') {
             actionArg = utils.getElementForNode(event.meta.node, event.meta.parent);
+            if(actionArg.sameNode(referenceElement)) {
+                referenceElement = this.children()[nodeIndex];
+            }
         } else {
             actionArg = event.meta.node;
         }
         } else {
             actionArg = event.meta.node;
         }