commit 4d1c939529c1 Author: Catalin Badea Date: Sun Sep 24 16:44:51 2017 -0400 Bug 1399091 - Avoid adding the same range to multiple selections. r=mats, a=sledru --HG-- extra : source : c3b24ef4281035ee00e09b3386fcbf2d672775c4 --- dom/base/nsRange.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git dom/base/nsRange.cpp dom/base/nsRange.cpp index 1e95ec629f55..8221450b828b 100644 --- dom/base/nsRange.cpp +++ dom/base/nsRange.cpp @@ -1048,12 +1048,19 @@ nsRange::SetSelection(mozilla::dom::Selection* aSelection) if (mSelection == aSelection) { return; } + // At least one of aSelection and mSelection must be null // aSelection will be null when we are removing from a selection // and a range can't be in more than one selection at a time, // thus mSelection must be null too. MOZ_ASSERT(!aSelection || !mSelection); + // Extra step in case our parent failed to ensure the above + // invariant. + if (aSelection && mSelection) { + mSelection->RemoveRange(this); + } + mSelection = aSelection; if (mSelection) { nsINode* commonAncestor = GetCommonAncestor();