editor: fixing handling nodeTextChange on text nodes belonging to custom-rendered...
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 26 May 2014 14:20:20 +0000 (16:20 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 28 May 2014 12:45:58 +0000 (14:45 +0200)
src/editor/modules/documentCanvas/canvas/canvas.test.js
src/editor/modules/documentCanvas/canvas/documentElement.js
src/editor/modules/documentCanvas/canvas/utils.js
src/editor/modules/documentCanvas/canvas/wlxmlListener.js

index 0654170..be4a8b9 100644 (file)
@@ -293,7 +293,11 @@ describe('Custom elements based on wlxml class attribute', function() {
                 onNodeAdded: function(event) {
                     void(event);
                     this.refresh2();
                 onNodeAdded: function(event) {
                     void(event);
                     this.refresh2();
-                }
+                },
+                onNodeTextChange: function(event) {
+                    this.header.text(event.meta.node.getText());
+                },
+                children: function() { return []; }
         });
 
         var c = getCanvasFromXML('<section><div class="testClass"><a></a></div></section>', [
         });
 
         var c = getCanvasFromXML('<section><div class="testClass"><a></a></div></section>', [
@@ -309,6 +313,14 @@ describe('Custom elements based on wlxml class attribute', function() {
         node.append({tagName: 'div'});
 
         expect(header.text()).to.equal('2', 'added div');
         node.append({tagName: 'div'});
 
         expect(header.text()).to.equal('2', 'added div');
+
+        var textNode = node.append({text: 'test'});
+
+        expect(header.text()).to.equal('3', 'added text node');
+        
+        textNode.setText('test2');
+
+        expect(header.text()).to.equal('test2', 'text node change handled');
     });
 
     describe('Handling unknown class', function() {
     });
 
     describe('Handling unknown class', function() {
index 948e8df..99a12f5 100644 (file)
@@ -226,6 +226,9 @@ $.extend(DocumentTextElement.prototype, {
             this.dom.contents()[0].data = text;
         }
     },
             this.dom.contents()[0].data = text;
         }
     },
+    handle: function(event) {
+        this.setText(event.meta.node.getText());
+    },
     getText: function(options) {
         options = _.extend({raw: false}, options || {});
         var toret = this.dom.text();
     getText: function(options) {
         options = _.extend({raw: false}, options || {});
         var toret = this.dom.text();
index 1df3f82..4e262a0 100644 (file)
@@ -58,7 +58,7 @@ var _getElementForTextNode = function(textNode, withParent) {
             return true;
         }
     });
             return true;
         }
     });
-    return toret;
+    return toret || parentElement;
 };
 
 var getElementForDetachedNode = function(node, originalParent) {
 };
 
 var getElementForDetachedNode = function(node, originalParent) {
index 02dc657..d107612 100644 (file)
@@ -75,7 +75,7 @@ var handlers = {
     },
     nodeTextChange: function(event) {
         var element = utils.getElementForNode(event.meta.node);
     },
     nodeTextChange: function(event) {
         var element = utils.getElementForNode(event.meta.node);
-        element.setText(event.meta.node.getText());
+        element.handle(event);
     },
 
     metadataChanged: _metadataEventHandler,
     },
 
     metadataChanged: _metadataEventHandler,