integration wip: listens for text changes in node family tree
[fnpeditor.git] / src / editor / modules / documentCanvas / canvas / canvas.js
index 97ad592..a4785ad 100644 (file)
@@ -13,9 +13,9 @@ define([
 var Canvas = function(wlxmlDocument, publisher) {
     this.eventBus = _.extend({}, Backbone.Events);
     this.wrapper = $('<div>').addClass('canvas-wrapper').attr('contenteditable', true);
+    this.wlxmlListener = wlxmlListener.create(this);
     this.loadWlxmlDocument(wlxmlDocument);
     this.publisher = publisher ? publisher : function() {};
-    this.wlxmlListener = wlxmlListener.create(this);
 };
 
 $.extend(Canvas.prototype, {
@@ -63,6 +63,9 @@ $.extend(Canvas.prototype, {
                     }
                     observer.observe(canvas.d[0], config);
                     canvas.publisher('contentChanged');
+
+                    var textElement = canvas.getDocumentElement(mutation.target);
+                    textElement.data('wlxmlNode').setText(mutation.target.data);
                 }
             });
         });
@@ -264,7 +267,7 @@ $.extend(Canvas.prototype, {
             if(params.caretTo || !textElementToLand.sameNode(this.getCursor().getPosition().element))
                 this._moveCaretToTextElement(textElementToLand, params.caretTo); // as method on element?
             if(!(textElementToLand.sameNode(currentTextElement)))
-                this.publisher('currentTextElementSet', textElementToLand);
+                this.publisher('currentTextElementSet', textElementToLand.data('wlxmlNode'));
         } else {
             document.getSelection().removeAllRanges();
         }