From 33c856dd7117df4cf8a272f2c896ba1760afdc3c Mon Sep 17 00:00:00 2001 From: Fedor Date: Thu, 7 May 2020 14:45:29 +0300 Subject: [PATCH] Improve handling of multiple selections. --- editor/libeditor/HTMLEditor.cpp | 10 ++++++++-- layout/generic/nsSelection.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp index 368f7a3e9..532da7a15 100644 --- a/editor/libeditor/HTMLEditor.cpp +++ b/editor/libeditor/HTMLEditor.cpp @@ -3344,12 +3344,18 @@ HTMLEditor::GetIsSelectionEditable(bool* aIsSelectionEditable) RefPtr selection = GetSelection(); NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); + nsINode* anchorNode = selection->GetAnchorNode(); + nsINode* focusNode = selection->GetFocusNode(); + if (!anchorNode || !focusNode) { + return NS_ERROR_FAILURE; + } + // Per the editing spec as of June 2012: we have to have a selection whose // start and end nodes are editable, and which share an ancestor editing // host. (Bug 766387.) *aIsSelectionEditable = selection->RangeCount() && - selection->GetAnchorNode()->IsEditable() && - selection->GetFocusNode()->IsEditable(); + anchorNode->IsEditable() && + focusNode->IsEditable(); if (*aIsSelectionEditable) { nsINode* commonAncestor = diff --git a/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp index f2959dc9d..5ccb2d8bf 100644 --- a/layout/generic/nsSelection.cpp +++ b/layout/generic/nsSelection.cpp @@ -3844,7 +3844,7 @@ Selection::AddItem(nsRange* aItem, int32_t* aOutIndex, bool aNoStartSelect) if (mUserInitiated) { AutoTArray, 4> rangesToAdd; - *aOutIndex = -1; + *aOutIndex = int32_t(mRanges.Length()) - 1; nsIDocument* doc = GetParentObject(); bool selectEventsEnabled =