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

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

index d806c69..45ee8ae 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,7 @@
 2010-10-18  Stanislas Rolland  <typo3@sjbr.ca>
 
        * Added feature #16047: htmlArea RTE: Add word count in the status bar
+       * Fixed bug #16050: htmlArea RTE: Backspacing in empty editing area may raise js error
 
 2010-10-18  Steffen Gebert  <steffen@steffen-gebert.de>
 
index 0e0ba1f..f645c20 100644 (file)
@@ -1,6 +1,7 @@
 2010-10-18  Stanislas Rolland  <typo3@sjbr.ca>
 
        * Added feature #16047: htmlArea RTE: Add word count in the status bar
+       * Fixed bug #16050: htmlArea RTE: Backspacing in empty editing area may raise js error
 
 2010-10-17  Stanislas Rolland  <typo3@sjbr.ca>
 
index 56e039d..a0b7668 100644 (file)
@@ -508,7 +508,9 @@ HTMLArea.Editor.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)) {
@@ -516,20 +518,27 @@ HTMLArea.Editor.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);
+                                       }
                                }
                        }
                }