Improve handling of multiple selections.

This commit is contained in:
Fedor 2020-05-07 14:45:29 +03:00
parent 25e72e5fea
commit 33c856dd71
2 changed files with 9 additions and 3 deletions

View File

@ -3344,12 +3344,18 @@ HTMLEditor::GetIsSelectionEditable(bool* aIsSelectionEditable)
RefPtr<Selection> selection = GetSelection(); RefPtr<Selection> selection = GetSelection();
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); 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 // 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 // start and end nodes are editable, and which share an ancestor editing
// host. (Bug 766387.) // host. (Bug 766387.)
*aIsSelectionEditable = selection->RangeCount() && *aIsSelectionEditable = selection->RangeCount() &&
selection->GetAnchorNode()->IsEditable() && anchorNode->IsEditable() &&
selection->GetFocusNode()->IsEditable(); focusNode->IsEditable();
if (*aIsSelectionEditable) { if (*aIsSelectionEditable) {
nsINode* commonAncestor = nsINode* commonAncestor =

View File

@ -3844,7 +3844,7 @@ Selection::AddItem(nsRange* aItem, int32_t* aOutIndex, bool aNoStartSelect)
if (mUserInitiated) { if (mUserInitiated) {
AutoTArray<RefPtr<nsRange>, 4> rangesToAdd; AutoTArray<RefPtr<nsRange>, 4> rangesToAdd;
*aOutIndex = -1; *aOutIndex = int32_t(mRanges.Length()) - 1;
nsIDocument* doc = GetParentObject(); nsIDocument* doc = GetParentObject();
bool selectEventsEnabled = bool selectEventsEnabled =