Wrapping text node containing DocumentTextElement's text
[fnpeditor.git] / modules / documentCanvas / canvas / canvas.js
index e6b8135..cf46d5e 100644 (file)
@@ -22,7 +22,8 @@ $.extend(Canvas.prototype, {
                 var currentTag = $(this);
                 if(currentTag.attr('wlxml-tag'))
                     return;
-                var toret = $('<div>').attr('wlxml-tag', currentTag.prop('tagName').toLowerCase());
+                var toret = $('<div>')
+                    .attr('wlxml-tag', currentTag.prop('tagName').toLowerCase());
                 //toret.attr('id', 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}));
                 for(var i = 0; i < this.attributes.length; i++) {
                     var attr = this.attributes.item(i);
@@ -57,9 +58,15 @@ $.extend(Canvas.prototype, {
                         this.data = $.trim(this.data);
                         if(this.data.length === 0 && oldLength > 0 && el.parent().contents().length === 1)
                             this.data = ' ';
-                        if(this.data.length === 0)
+                        if(this.data.length === 0) {
                             $(this).remove();
+                            return true; // continue
+                        }
                     }
+
+                    var wrapper = documentElement.DocumentTextElement.create({text: this.data});
+                    $(this).before(wrapper.dom());
+                    $(this).remove();
                 });
             
             this.d = wrapper.children(0);
@@ -72,7 +79,7 @@ $.extend(Canvas.prototype, {
     doc: function() {
         if(this.d === null)
             return null;
-        return documentElement.wrap(this.d.get(0), this); //{wlxmlTag: this.d.prop('tagName')};
+        return documentElement.DocumentNodeElement.fromHTMLElement(this.d.get(0), this); //{wlxmlTag: this.d.prop('tagName')};
     },
 
     wrapText: function(params) {
@@ -117,7 +124,7 @@ $.extend(Canvas.prototype, {
     },
     getDocumentElement: function(from) {
         if(from instanceof HTMLElement || from instanceof Text) {
-           return documentElement.wrap(from, this);
+           return documentElement.DocumentElement.fromHTMLElement(from, this);
         }
     },
     getCursor: function() {