empty text nodes after spans
authorJan Szejko <janek37@gmail.com>
Thu, 9 Mar 2017 14:16:00 +0000 (15:16 +0100)
committerJan Szejko <janek37@gmail.com>
Tue, 27 Mar 2018 15:06:22 +0000 (17:06 +0200)
(cherry picked from commit 091b7b5)

src/editor/plugins/core/core.js
src/wlxml/wlxml.js

index c2c5ffa..0221ed0 100644 (file)
@@ -120,6 +120,8 @@ plugin.documentExtension.textNode.transformations = {
                 parent.contents().some(function(n) {
                     return move(n, newNode);
                 });
                 parent.contents().some(function(n) {
                     return move(n, newNode);
                 });
+                // span can't be the last node
+                newNode.append({'text': ''});
                 if(newNodes.second.contents()[0].getText().length === 0) {
                     var textNode = newNodes.second.contents()[0];
                     newNodes.second.detach();
                 if(newNodes.second.contents()[0].getText().length === 0) {
                     var textNode = newNodes.second.contents()[0];
                     newNodes.second.detach();
@@ -521,6 +523,10 @@ var createWrapTextAction = function(createParams) {
                                 offsetEnd: params.fragment.endOffset,
                                 textNodeIdx: [params.fragment.startNode.getIndex(), params.fragment.endNode.getIndex()]
                             });
                                 offsetEnd: params.fragment.endOffset,
                                 textNodeIdx: [params.fragment.startNode.getIndex(), params.fragment.endNode.getIndex()]
                             });
+                            if(wrapper.next() === null) {
+                                // span can't be the last node
+                                parent.append({text: ''});
+                            }
                                 
                             lastTextNode = wrapper.getLastTextNode();
                             if(lastTextNode) {
                                 
                             lastTextNode = wrapper.getLastTextNode();
                             if(lastTextNode) {
index d05eb64..ce0ac0a 100644 (file)
@@ -239,7 +239,9 @@ $.extend(WLXMLDocument.prototype, {
         });
         nativeNode.normalize();
         $(nativeNode).find('*').each(function() {
         });
         nativeNode.normalize();
         $(nativeNode).find('*').each(function() {
-            if (this.childNodes.length === 0) {
+            var emptyNode = this.childNodes.length === 0;
+            var endsWithSpan = !emptyNode && this.childNodes[this.childNodes.length - 1].nodeName.toLowerCase() === 'span';
+            if(emptyNode || endsWithSpan) {
                 var fakeTextNode = window.document.createTextNode("");
                 this.appendChild(fakeTextNode);
             }
                 var fakeTextNode = window.document.createTextNode("");
                 this.appendChild(fakeTextNode);
             }
@@ -295,7 +297,7 @@ $.extend(WLXMLDocument.prototype, {
                     }
                 }
 
                     }
                 }
 
-                if(!text.transformed  && !onlyChild) {
+                if(!text.transformed && !(el.is(':only-child') || (el.is(':last-child') && hasSpanBefore))) {
                     addInfo(text.original, 'below');
                     el.remove();
                     return true; // continue
                     addInfo(text.original, 'below');
                     el.remove();
                     return true; // continue