Index: typo3/sysext/rtehtmlarea/htmlarea/htmlarea-gecko.js
===================================================================
--- typo3/sysext/rtehtmlarea/htmlarea/htmlarea-gecko.js	(revision 2741)
+++ typo3/sysext/rtehtmlarea/htmlarea/htmlarea-gecko.js	(working copy)
@@ -96,6 +96,28 @@
 };
 
 /*
+ * Empty the selection object
+ */
+HTMLArea.prototype.emptySelection = function(sel) {
+	if (HTMLArea.is_safari) {
+		sel.empty();
+	} else {
+		sel.removeAllRanges();
+	}
+};
+
+/*
+ * Add a range to the selection
+ */
+HTMLArea.prototype.addRangeToSelection = function(sel, range) {
+	if (HTMLArea.is_safari) {
+		sel.setBaseAndExtent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
+	} else {
+		sel.addRange(range);
+	}
+};
+
+/*
  * Create a range for the current selection
  */
 HTMLArea.prototype._createRange = function(sel) {
@@ -135,13 +157,8 @@
 	if (node.nodeType == 1 && node.tagName.toLowerCase() == "body") range.selectNodeContents(node);
 		else range.selectNode(node);
 	if ((typeof(pos) != "undefined")) range.collapse(pos);
-	if (HTMLArea.is_safari) {
-		sel.empty();
-		sel.setBaseAndExtent(range.startContainer,range.startOffset,range.endContainer,range.endOffset);
-	} else {
-		sel.removeAllRanges();
-		sel.addRange(range);
-	}
+	this.emptySelection(sel);
+	this.addRangeToSelection(sel, range);
 };
 
 /*
@@ -153,13 +170,8 @@
 	var range = this._doc.createRange();
 	range.selectNodeContents(node);
 	if ((typeof(pos) != "undefined")) range.collapse(pos);
-	if (HTMLArea.is_safari) {
-		sel.empty();
-		sel.setBaseAndExtent(range.startContainer,range.startOffset,range.endContainer,range.endOffset);
-	} else {
-		sel.removeAllRanges();
-		sel.addRange(range);
-	}
+	this.emptySelection(sel);
+	this.addRangeToSelection(sel, range);
 };
 
 /*
@@ -192,19 +204,11 @@
 	if (typeof(range) === "undefined") {
 		var range = this._createRange(sel);
 	}
-	try {
-		var p = range.commonAncestorContainer;
-		if (!range.collapsed && range.startContainer == range.endContainer &&
-				range.startOffset - range.endOffset <= 1 && range.startContainer.hasChildNodes()) {
-			p = range.startContainer.childNodes[range.startOffset];
-		}
-		while (p.nodeType == 3) {
-			p = p.parentNode;
-		}
-		return p;
-	} catch (e) {
-		return this._doc.body;
+	var p = range.commonAncestorContainer;
+	while (p.nodeType == 3) {
+		p = p.parentNode;
 	}
+	return p;
 };
 
 /*
@@ -246,8 +250,7 @@
 		node = range.startContainer,
 		pos = range.startOffset,
 		selnode = toBeInserted;
-	if (HTMLArea.is_safari) sel.empty();
-		else sel.removeAllRanges();
+	this.emptySelection(sel);
 	range.deleteContents();
 	switch (node.nodeType) {
 	    case 3: // Node.TEXT_NODE: we have to split it at the caret position.
@@ -256,8 +259,7 @@
 			range = this._createRange();
 			range.setEnd(node, pos + toBeInserted.length);
 			range.setStart(node, pos + toBeInserted.length);
-			if (HTMLArea.is_safari) sel.setBaseAndExtent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);
-				else sel.addRange(range);
+			this.addRangeToSelection(sel, range);
 		} else {
 			node = node.splitText(pos);
 			if (toBeInserted.nodeType == 11) selnode = selnode.lastChild;
@@ -345,6 +347,7 @@
 	var editor = target.editor;
 	target.blur();
 	editor.selectNode(target.el);
+	editor._statusBarTree.selected = target.el;
 	editor.updateToolbar(true);
 	switch (ev.type) {
 		case "click" :
@@ -426,13 +429,8 @@
 			r.setStartBefore(newr);
 			r.setEndAfter(newr);
 			r.extractContents();
-			if(HTMLArea.is_safari) {
-				sel.empty();
-				sel.setBaseAndExtent(r.startContainer,r.startOffset,r.endContainer,r.endOffset);
-			} else {
-				sel.removeAllRanges();
-				sel.addRange(r);
-			}
+			this.emptySelection(sel);
+			this.addRangeToSelection(sel, r);
 			return true;
 		}
 	},10);
@@ -442,7 +440,7 @@
 /*
  * Enter event handler
  */
-HTMLArea.prototype._checkInsertP = function(ev) {
+HTMLArea.prototype._checkInsertP = function() {
 	var editor = this;
 	this.focusEditor();
 	var i, left, right, rangeClone,
@@ -459,9 +457,10 @@
 			break;
 		}
 	}
-	if (!range.collapsed) range.deleteContents();
-	if (HTMLArea.is_safari) sel.empty();
-		else sel.removeAllRanges();
+	if (!range.collapsed) {
+		range.deleteContents();
+	}
+	this.emptySelection(sel);
 	if (!block || /^(td|div)$/i.test(block.tagName)) {
 		if (!block) var block = doc.body;
 		if (/\S/.test(HTMLArea.getInnerText(block))) {
@@ -475,8 +474,13 @@
 				left.appendChild(doc.createElement('br'));
 			}
 			left.normalize();
+			range.setStartAfter(left);
 			range.setEndAfter(block.lastChild);
-			range.surroundContents(right = doc.createElement('p'));
+				// Working around Safari issue: The following gives a range exception
+				// range.surroundContents(right = doc.createElement('p'));
+			right = doc.createElement('p');
+			right.appendChild(range.extractContents());
+			block.appendChild(right);
 				// Remove any element created empty
 			a = right.previousSibling;
 			if (a && !/\S/.test(HTMLArea.getInnerText(a))) HTMLArea.removeFromParent(a);
@@ -490,9 +494,9 @@
 		} else {
 			range = doc.createRange();
 			var first = block.firstChild;
-			block.removeChild(first);
+			if (first) block.removeChild(first);
 			block.appendChild(right = doc.createElement('p'));
-			right.appendChild(first);
+			if (first) right.appendChild(first);
 		}
 		range.selectNodeContents(right);
 	} else {
@@ -523,10 +527,9 @@
 		}
 	}
 	range.collapse(true);
-	if (HTMLArea.is_safari) sel.setBaseAndExtent(r.startContainer,r.startOffset,r.endContainer,r.endOffset);
-		else sel.addRange(range);
+	this.emptySelection(sel);
+	this.addRangeToSelection(sel, range);
 	this.scrollToCaret();
-	return true;
 };
 
 /*
Index: typo3/sysext/rtehtmlarea/htmlarea/htmlarea.js
===================================================================
--- typo3/sysext/rtehtmlarea/htmlarea/htmlarea.js	(revision 2741)
+++ typo3/sysext/rtehtmlarea/htmlarea/htmlarea.js	(working copy)
@@ -2298,13 +2298,8 @@
 				sel = this._getSelection();
 				var r = this._createRange(sel).cloneRange();
 				r.collapse(false);
-				if(HTMLArea.is_safari) {
-					sel.empty();
-					sel.setBaseAndExtent(r.startContainer,r.startOffset,r.endContainer,r.endOffset);
-				} else {
-					sel.removeAllRanges();
-					sel.addRange(r);
-				}
+				this.emptySelection(sel);
+				this.addRangeToSelection(sel, r);
 			}
 		}
 		break;
@@ -2327,7 +2322,7 @@
 		while (owner.parentElement) { owner = owner.parentElement; }
 	}
 	var editor = RTEarea[owner._editorNo]["editor"];
-	var keyEvent = ((HTMLArea.is_ie || HTMLArea.is_safari) && ev.type == "keydown") || (!HTMLArea.is_ie && ev.type == "keypress");
+	var keyEvent = (HTMLArea.is_ie && ev.type == "keydown") || (HTMLArea.is_gecko && ev.type == "keypress");
 	editor.focusEditor();
 
 	if(keyEvent) {
@@ -2428,10 +2423,12 @@
 			switch (ev.keyCode) {
 				case 13	: // KEY enter
 					if (HTMLArea.is_gecko && !ev.shiftKey && !editor.config.disableEnterParagraphs) {
-						if (editor._checkInsertP(ev)) HTMLArea._stopEvent(ev);
+						editor._checkInsertP();
+						HTMLArea._stopEvent(ev);
 							// update the toolbar state after some time
 						if (editor._timerToolbar) window.clearTimeout(editor._timerToolbar);
 						editor._timerToolbar = window.setTimeout("HTMLArea.updateToolbar(" + editor._editorNumber + ");", 50);
+						return false;
 					}
 					break;
 				case 8	: // KEY backspace
Index: typo3/sysext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php
===================================================================
--- typo3/sysext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php	(revision 2741)
+++ typo3/sysext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php	(working copy)
@@ -229,7 +229,7 @@
 			// Preloading the pageStyle
 		$filename = trim($this->thisConfig['contentCSS']) ? trim($this->thisConfig['contentCSS']) : 'EXT:' . $this->ID . '/htmlarea/plugins/DynamicCSS/dynamiccss.css';
 		$additionalCode_loadCSS = '
-		<link rel="alternate stylesheet" type="text/css" href="' . $this->getFullFileName($filename) . '" />';
+		<link rel="alternate stylesheet" type="text/css" href="' . $this->getFullFileName($filename) . '" title="HTMLArea RTE Content CSS" />';
 
 			// Loading the editor skin
 		$skinFilename = trim($this->thisConfig['skin']) ? trim($this->thisConfig['skin']) : 'EXT:' . $this->ID . '/htmlarea/skins/default/htmlarea.css';
