Bug 1423097 - part 3: Fix new orange caused by an existing bug of EditorBase::DeleteSelectionAndCreateElement() r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 07 Dec 2017 13:57:35 +0900
changeset 710243 6ad6ff45e6464aa199451a1ea3c317ed8381b309
parent 710242 f1a78f0266703368b6cc75416ef2ac4333e4927c
child 710244 2771c1233ed17ee1bdd8d596da5ea454c3a00b40
push id92792
push usermasayuki@d-toybox.com
push dateFri, 08 Dec 2017 23:53:41 +0000
reviewersm_kato
bugs1423097
milestone59.0a1
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
editor/libeditor/EditorBase.cpp
--- 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();