Bug 456944 - Crash when spell checking selection changes, r=smaug, sr=roc
authorAlexander Surkov <surkov.alexander@gmail.com>
Wed, 08 Oct 2008 20:53:14 +0800
changeset 20139 681e49004d912788cd104fc6d8b3be8a50d2d3ac
parent 20138 851c5da59738ee9d24a76cad3547ff585eaf0dbd
child 20140 32bfbcb0e5ddfbdcc77e1c7d1326f8c6a40635e5
push idunknown
push userunknown
push dateunknown
reviewerssmaug, roc
bugs456944
milestone1.9.1b2pre
Bug 456944 - Crash when spell checking selection changes, r=smaug, sr=roc
layout/generic/nsSelection.cpp
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -5888,31 +5888,30 @@ nsTypedSelection::RemoveRange(nsIDOMRang
   nsCOMArray<nsIDOMRange> affectedRanges;
   rv = GetRangesForIntervalCOMArray(beginNode, beginOffset,
                                     endNode, endOffset,
                                     PR_TRUE, &affectedRanges);
   NS_ENSURE_SUCCESS(rv, rv);
   for (PRInt32 i = 0; i < affectedRanges.Count(); i ++)
     selectFrames(presContext, affectedRanges[i], PR_TRUE);
 
-  // When the selection is user-created it makes sense to scroll the range
-  // into view. The spell-check selection, however, is created and destroyed
-  // in the background. We don't want to scroll in this case or the view
-  // might appear to be moving randomly (bug 337871).
-  if (mType != nsISelectionController::SELECTION_SPELLCHECK &&
-      aRange == mAnchorFocusRange.get())
-  {
-    PRInt32 cnt = mRanges.Length();
-    if (cnt > 0)
-    {
-      setAnchorFocusRange(cnt - 1);//reset anchor to LAST range.
+  PRInt32 cnt = mRanges.Length();
+  if (aRange == mAnchorFocusRange.get()) {
+    // Reset anchor to LAST range or clear it if there are no ranges.
+    setAnchorFocusRange(cnt - 1);
+
+    // When the selection is user-created it makes sense to scroll the range
+    // into view. The spell-check selection, however, is created and destroyed
+    // in the background. We don't want to scroll in this case or the view
+    // might appear to be moving randomly (bug 337871).
+    if (mType != nsISelectionController::SELECTION_SPELLCHECK && cnt > 0)
       ScrollIntoView(nsISelectionController::SELECTION_FOCUS_REGION, PR_FALSE,
                      PR_FALSE);
-    }
-  }
+  }
+
   if (!mFrameSelection)
     return NS_OK;//nothing to do
   return mFrameSelection->NotifySelectionListeners(GetType());
 }
 
 
 
 /*