diff --git a/dom/base/Selection.cpp b/dom/base/Selection.cpp index 89f87c102476..4db2e580b67f 100644 --- a/dom/base/Selection.cpp +++ b/dom/base/Selection.cpp @@ -541,10 +541,7 @@ Selection::~Selection() { Disconnect(); } void Selection::Disconnect() { SetAnchorFocusRange(-1); - uint32_t count = mStyledRanges.mRanges.Length(); - for (uint32_t i = 0; i < count; ++i) { - mStyledRanges.mRanges[i].mRange->UnregisterSelection(); - } + mStyledRanges.UnregisterSelection(); if (mAutoScrollTimer) { mAutoScrollTimer->Stop(); @@ -1109,8 +1106,8 @@ nsresult Selection::RemoveCollapsedRanges() { nsresult Selection::Clear(nsPresContext* aPresContext) { SetAnchorFocusRange(-1); + mStyledRanges.UnregisterSelection(); for (uint32_t i = 0; i < mStyledRanges.mRanges.Length(); ++i) { - mStyledRanges.mRanges[i].mRange->UnregisterSelection(); SelectFrames(aPresContext, mStyledRanges.mRanges[i].mRange, false); } mStyledRanges.mRanges.Clear(); @@ -1749,6 +1746,13 @@ void Selection::SetAncestorLimiter(nsIContent* aLimiter) { } } +void Selection::StyledRanges::UnregisterSelection() { + uint32_t count = mRanges.Length(); + for (uint32_t i = 0; i < count; ++i) { + mRanges[i].mRange->UnregisterSelection(); + } +} + StyledRange* Selection::StyledRanges::FindRangeData(nsRange* aRange) { NS_ENSURE_TRUE(aRange, nullptr); for (uint32_t i = 0; i < mRanges.Length(); i++) { diff --git a/dom/base/Selection.h b/dom/base/Selection.h index 96427a1cdc50..c345d958c66e 100644 --- a/dom/base/Selection.h +++ b/dom/base/Selection.h @@ -841,6 +841,8 @@ class Selection final : public nsSupportsWeakReference, static nsresult SubtractRange(StyledRange& aRange, nsRange& aSubtract, nsTArray* aOutput); + void UnregisterSelection(); + // These are the ranges inside this selection. They are kept sorted in order // of DOM start position. //