[BUGFIX] RTE: WebKit may insert a span tag when backspacing a heading 35/36035/5
authorStanislas Rolland <typo3@sjbr.ca>
Fri, 16 Jan 2015 02:25:52 +0000 (21:25 -0500)
committerStanislas Rolland <typo3@sjbr.ca>
Sat, 17 Jan 2015 04:41:26 +0000 (05:41 +0100)
It may happen, for example, when deleting an empty heading which is
followed by a paragraph, or when backspacing a paragraph or heading
which becomes merged with a preceding heading.
Remove the unwanted span element.

Releases: master, 6.2
Resolves: #59562
Change-Id: I820dfd0e39f2686e07d10b86af6deff59a57cc38
Reviewed-on: http://review.typo3.org/36035
Reviewed-by: Stanislas Rolland <typo3@sjbr.ca>
Tested-by: Stanislas Rolland <typo3@sjbr.ca>
typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/HTMLArea/DOM/Node.js
typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/HTMLArea/DOM/Selection.js

index 52456a7..40c3186 100644 (file)
@@ -245,7 +245,7 @@ define('TYPO3/CMS/Rtehtmlarea/HTMLArea/DOM/Node',
                                if (Dom.hasClass(spans[i], 'Apple-style-span')) {
                                        this.removeMarkup(spans[i]);
                                }
-                               if (/^(li)$/i.test(spans[i].parentNode.nodeName) && (spans[i].style.cssText.indexOf('line-height') !== -1 || spans[i].style.cssText.indexOf('font-family') !== -1 || spans[i].style.cssText.indexOf('font-size') !== -1)) {
+                               if (/^(li|h[1-6])$/i.test(spans[i].parentNode.nodeName) && (spans[i].style.cssText.indexOf('line-height') !== -1 || spans[i].style.cssText.indexOf('font-family') !== -1 || spans[i].style.cssText.indexOf('font-size') !== -1)) {
                                        this.removeMarkup(spans[i]);
                                }
                        }
index c6096c0..9565d44 100644 (file)
@@ -726,29 +726,38 @@ define('TYPO3/CMS/Rtehtmlarea/HTMLArea/DOM/Selection',
                                var range = self.createRange();
                                var startContainer = range.startContainer;
                                var startOffset = range.startOffset;
-                                       // If the selection is collapsed...
+                               // If the selection is collapsed...
                                if (self.isEmpty()) {
-                                               // ... and the cursor lies in a direct child of body...
+                                       // ... and the cursor lies in a direct child of body...
                                        if (/^(body)$/i.test(startContainer.nodeName)) {
                                                var node = startContainer.childNodes[startOffset-1];
                                        } else if (/^(body)$/i.test(startContainer.parentNode.nodeName)) {
                                                var node = startContainer;
+                                       // ... or, in Google, a span tag may have been inserted inside a heading element
+                                       } else if (UserAgent.isWebKit && /^(#text)$/i.test(startContainer.nodeName)) {
+                                               var node = startContainer.parentNode;
+                                               if (/^(h[1-6])$/i.test(node.nodeName)) {
+                                                       self.editor.getDomNode().cleanAppleStyleSpans(node);
+                                               } else if (node.parentNode && /^(h[1-6])$/i.test(node.parentNode.nodeName)) {
+                                                       self.editor.getDomNode().cleanAppleStyleSpans(node.parentNode);
+                                               }
+                                               return false;
                                        } else {
                                                return false;
                                        }
-                                               // ... which is a br or text node containing no non-whitespace character...
+                                       // ... which is a br or text node containing no non-whitespace character...
                                        node.normalize();
                                        if (/^(br|#text)$/i.test(node.nodeName) && !/\S/.test(node.textContent)) {
-                                                       // Get a meaningful previous sibling in which to reposition de cursor
+                                               // Get a meaningful previous sibling in which to reposition de cursor
                                                var previousSibling = node.previousSibling;
                                                while (previousSibling && /^(br|#text)$/i.test(previousSibling.nodeName) && !/\S/.test(previousSibling.textContent)) {
                                                        previousSibling = previousSibling.previousSibling;
                                                }
-                                                       // If there is no meaningful previous sibling, the cursor is at the start of body or the start of a direct child of body
+                                               // If there is no meaningful previous sibling, the cursor is at the start of body or the start of a direct child of body
                                                if (previousSibling) {
-                                                               // Remove the node
+                                                       // Remove the node
                                                        Dom.removeFromParent(node);
-                                                               // Position the cursor
+                                                       // Position the cursor
                                                        if (/^(ol|ul|dl)$/i.test(previousSibling.nodeName)) {
                                                                self.selectNodeContents(previousSibling.lastChild, false);
                                                        } else if (/^(table)$/i.test(previousSibling.nodeName)) {
@@ -759,7 +768,7 @@ define('TYPO3/CMS/Rtehtmlarea/HTMLArea/DOM/Selection',
                                                                self.selectNodeContents(previousSibling, false);
                                                        }
                                                }
-                                               // ... or the only child of body and having no child (IE) or only a br child (FF)
+                                       // ... or the only child of body and having no child (IE) or only a br child (FF)
                                        } else if (
                                                        /^(body)$/i.test(node.parentNode.nodeName)
                                                        && !/\S/.test(node.parentNode.textContent)