[BUGFIX] RTE: Inconsistent delete behaviour 97/33497/5
authorStanislas Rolland <typo3@sjbr.ca>
Thu, 23 Oct 2014 22:18:48 +0000 (18:18 -0400)
committerStanislas Rolland <typo3@sjbr.ca>
Wed, 5 Nov 2014 18:47:02 +0000 (19:47 +0100)
In Firefox, depending on how we delete something in RTE, we get
different results.
This change makes the results consistent and identical in all browsers.

Releases: master, 6.2
Resolves: #61747
Change-Id: I7bc15992efb0703b96a59adf6d14484249d9f785
Reviewed-on: http://review.typo3.org/33497
Reviewed-by: Stanislas Rolland <typo3@sjbr.ca>
Tested-by: Stanislas Rolland <typo3@sjbr.ca>
typo3/sysext/rtehtmlarea/htmlarea/DOM/HTMLArea.DOM.Selection.js
typo3/sysext/rtehtmlarea/htmlarea/Editor/HTMLArea.Iframe.js

index f738152..5b8cd9e 100644 (file)
@@ -683,20 +683,21 @@ HTMLArea.DOM.Selection = Ext.extend(HTMLArea.DOM.Selection, {
                                if (self.isEmpty()) {
                                                // ... and the cursor lies in a direct child of body...
                                        if (/^(body)$/i.test(startContainer.nodeName)) {
-                                               var node = startContainer.childNodes[startOffset];
+                                               var node = startContainer.childNodes[startOffset-1];
                                        } else if (/^(body)$/i.test(startContainer.parentNode.nodeName)) {
                                                var node = startContainer;
                                        } 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
                                                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
+                                                       // 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
                                                        HTMLArea.DOM.removeFromParent(node);
@@ -711,6 +712,16 @@ HTMLArea.DOM.Selection = Ext.extend(HTMLArea.DOM.Selection, {
                                                                self.selectNodeContents(previousSibling, false);
                                                        }
                                                }
+                                               // ... 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)
+                                                       && (node.childNodes.length === 0 || (node.childNodes.length === 1 && /^(br)$/i.test(node.firstChild.nodeName)))
+                                               ) {
+                                               var parentNode = node.parentNode;
+                                               HTMLArea.DOM.removeFromParent(node);
+                                               parentNode.innerHTML = '<br />';
+                                               self.selectNodeContents(parentNode, true);
                                        }
                                }
                        }, 10);
index fc156de..b8cd5f0 100644 (file)
@@ -372,7 +372,7 @@ HTMLArea.Iframe = Ext.extend(Ext.BoxComponent, {
                                scope: this
                        }
                ]);
-               if (HTMLArea.UserAgent.isGecko || HTMLArea.UserAgent.isIE) {
+               if (HTMLArea.UserAgent.isGecko || HTMLArea.UserAgent.isIE || HTMLArea.UserAgent.isWebKit) {
                        this.keyMap.addBinding(
                        {
                                key: [Ext.EventObject.BACKSPACE, Ext.EventObject.DELETE],