From a2bc0e0ec6da3a689fa08cb02a9d65889de60f7c Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sun, 12 Apr 2020 12:52:18 +0200 Subject: Issue #1512 - Improve handling of multiple selections. IsSelectionEditable should check whether the focus node and anchor node aren't null before trying to use them. This also changes the initialization of selections' aOutIndex to the last range in the selection as a fallback in case we don't add a range later (in AddItem) which could also end up with a null selection otherwise if the additional selection nodes are removed. --- editor/libeditor/HTMLEditor.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'editor/libeditor') 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 = -- cgit v1.2.3