Fixed bug #16050: htmlArea RTE: Backspacing in empty editing area may raise js error
authorStanislas Rolland <typo3@sjbr.ca>
Mon, 18 Oct 2010 23:16:42 +0000 (23:16 +0000)
committerStanislas Rolland <typo3@sjbr.ca>
Mon, 18 Oct 2010 23:16:42 +0000 (23:16 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/branches/TYPO3_4-3@9155 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/rtehtmlarea/ChangeLog
typo3/sysext/rtehtmlarea/htmlarea/htmlarea-gecko.js

index c882a6d..fdf88b7 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-10-18  Stanislas Rolland  <typo3@sjbr.ca>
+
+       * Fixed bug #16050: htmlArea RTE: Backspacing in empty editing area may raise js error
+
 2010-10-18  Xavier Perseguers  <typo3@perseguers.ch>
 
        * Fixed bug #1318: 'removeTag' does not remove closing tags
index 72c3f66..2d7613f 100644 (file)
@@ -1,3 +1,7 @@
+2010-10-18  Stanislas Rolland  <typo3@sjbr.ca>
+
+       * Fixed bug #16050: htmlArea RTE: Backspacing in empty editing area may raise js error
+
 2010-10-06  Stanislas Rolland  <typo3@sjbr.ca>
 
        * Fixed bug #15858: htlmArea RTE: Stylesheet access error in Google Chrome 7
index 043fc0b..d6c3290 100644 (file)
@@ -572,7 +572,9 @@ HTMLArea.prototype._checkBackspace = function() {
                        var range = self._createRange(selection);
                        var startContainer = range.startContainer;
                        var startOffset = range.startOffset;
+                               // If the selection is collapsed...
                        if (self._selectionEmpty()) {
+                                       // ... and the cursor lies in a direct child of body...
                                if (/^(body)$/i.test(startContainer.nodeName)) {
                                        var node = startContainer.childNodes[startOffset];
                                } else if (/^(body)$/i.test(startContainer.parentNode.nodeName)) {
@@ -580,20 +582,27 @@ HTMLArea.prototype._checkBackspace = function() {
                                } else {
                                        return false;
                                }
+                                       // ... which is a br or text node containing no non-whitespace character
                                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;
                                        }
-                                       HTMLArea.removeFromParent(node);
-                                       if (/^(ol|ul|dl)$/i.test(previousSibling.nodeName)) {
-                                               self.selectNodeContents(previousSibling.lastChild, false);
-                                       } else if (/^(table)$/i.test(previousSibling.nodeName)) {
-                                               self.selectNodeContents(previousSibling.rows[previousSibling.rows.length-1].cells[previousSibling.rows[previousSibling.rows.length-1].cells.length-1], false);
-                                       } else if (!/\S/.test(previousSibling.textContent) && previousSibling.firstChild) {
-                                               self.selectNode(previousSibling.firstChild, true);
-                                       } else {
-                                               self.selectNodeContents(previousSibling, false);
+                                               // If there is no meaningful previous sibling, the cursor is at the start of body
+                                       if (previousSibling) {
+                                                       // Remove the node
+                                               HTMLArea.removeFromParent(node);
+                                                       // Position the cursor
+                                               if (/^(ol|ul|dl)$/i.test(previousSibling.nodeName)) {
+                                                       self.selectNodeContents(previousSibling.lastChild, false);
+                                               } else if (/^(table)$/i.test(previousSibling.nodeName)) {
+                                                       self.selectNodeContents(previousSibling.rows[previousSibling.rows.length-1].cells[previousSibling.rows[previousSibling.rows.length-1].cells.length-1], false);
+                                               } else if (!/\S/.test(previousSibling.textContent) && previousSibling.firstChild) {
+                                                       self.selectNode(previousSibling.firstChild, true);
+                                               } else {
+                                                       self.selectNodeContents(previousSibling, false);
+                                               }
                                        }
                                }
                        }