Bug 1423097 - part 3: Fix new orange caused by an existing bug of EditorBase::DeleteSelectionAndCreateElement() r?m_kato
Even after EditorBase::DeleteSelectionAndCreateElement() creates a new element,
it tries to collapse selection with |pointToInsert| which is outdated after
inserting new element.
So, it should recompute the caret position with new DOM tree.
MozReview-Commit-ID: DKh2uhItIol
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -4485,21 +4485,23 @@ EditorBase::DeleteSelectionAndCreateElem
EditorRawDOMPoint pointToInsert(selection->AnchorRef());
if (!pointToInsert.IsSet()) {
return nullptr;
}
RefPtr<Element> newElement = CreateNode(&aTag, pointToInsert);
// We want the selection to be just after the new node
- DebugOnly<bool> advanced = pointToInsert.AdvanceOffset();
+ EditorRawDOMPoint afterNewElement(newElement);
+ MOZ_ASSERT(afterNewElement.IsSetAndValid());
+ DebugOnly<bool> advanced = afterNewElement.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to move offset next to the new element");
ErrorResult error;
- selection->Collapse(pointToInsert, error);
+ selection->Collapse(afterNewElement, error);
if (NS_WARN_IF(error.Failed())) {
// XXX Even if it succeeded to create new element, this returns error
// when Selection.Collapse() fails something. This could occur with
// mutation observer or mutation event listener.
error.SuppressException();
return nullptr;
}
return newElement.forget();