Fix browser bug workaround
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Thu, 15 Sep 2011 15:07:32 -0600
changeset 581 916f9a259380
parent 580 76a8d2c3e11f
child 582 d0760b6d50a5
Fix browser bug workaround

This fixes a bunch of broken createLink tests in Firefox 8.0a2.
implementation.js
--- a/implementation.js	Thu Sep 15 14:47:56 2011 -0600
+++ b/implementation.js	Thu Sep 15 15:07:32 2011 -0600
@@ -2963,12 +2963,15 @@
 	&& getActiveRange().startOffset != 0
 	&& getActiveRange().startOffset != getNodeLength(getActiveRange().startContainer)) {
 		// Account for browsers not following range mutation rules
-		var newNode = getActiveRange().startContainer.splitText(getActiveRange().startOffset);
 		var newActiveRange = document.createRange();
+		var newNode;
 		if (getActiveRange().startContainer == getActiveRange().endContainer) {
 			var newEndOffset = getActiveRange().endOffset - getActiveRange().startOffset;
+			newNode = getActiveRange().startContainer.splitText(getActiveRange().startOffset);
 			newActiveRange.setEnd(newNode, newEndOffset);
 			getActiveRange().setEnd(newNode, newEndOffset);
+		} else {
+			newNode = getActiveRange().startContainer.splitText(getActiveRange().startOffset);
 		}
 		newActiveRange.setStart(newNode, 0);
 		getSelection().removeAllRanges();