Bug 1420415 - TextEditor::CreateBRImpl() needs to make pointToInsertBrNode store mOffset before calling EditorBase::CreateNode() r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 24 Nov 2017 23:17:38 +0900
changeset 703584 07e1f1c00bc5ea625344b9826bb0582434949152
parent 703549 da90245d47b17c750560dedb5cbe1973181166e3
child 703674 26e7e9577bda6c4431ae9d13587c0690c534c42c
push id90871
push usermasayuki@d-toybox.com
push dateMon, 27 Nov 2017 05:48:55 +0000
reviewersm_kato
bugs1420415, 1408227
milestone59.0a1
Bug 1420415 - TextEditor::CreateBRImpl() needs to make pointToInsertBrNode store mOffset before calling EditorBase::CreateNode() r?m_kato When TextEditor::CreateBRImpl() splits a text node before inserting new <br> element, it initializes pointToInsertBrNode only with the right text node. Then, it refers its Offset() after inserting new <br> node before the point. Therefore, the offset is computed with the new DOM tree. So, adding 1 to the offset is redundant only in this case. So, before calling CreateNode(), it needs to make pointToInsertBrNode store offset with calling its Offset(). Note that this ugly code will be replaced with patches for bug 1408227. Additionally, this doesn't use AutoEditorDOMPointChildInvalidator because it's not available in 58 but we need to uplift this patch. Finally, I'm not sure how to check this in automated tests. Therefore, this patch doesn't include automated tests. MozReview-Commit-ID: IaQBonoGawR
editor/libeditor/TextEditor.cpp
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -461,16 +461,19 @@ TextEditor::CreateBRImpl(nsCOMPtr<nsIDOM
       nsCOMPtr<nsIContent> newLeftNode = SplitNode(atStartOfNewLine, error);
       if (NS_WARN_IF(error.Failed())) {
         return error.StealNSResult();
       }
       // The right node offset in the parent is now changed.  Recompute it.
       pointToInsertBrNode.Set(node);
       Unused << newLeftNode;
     }
+    // Lock the offset of pointToInsertBrNode because it'll be referred after
+    // inserting a new <br> node before it.
+    Unused << pointToInsertBrNode.Offset();
     // create br
     brNode = CreateNode(nsGkAtoms::br, pointToInsertBrNode);
     if (NS_WARN_IF(!brNode)) {
       return NS_ERROR_FAILURE;
     }
     *aInOutParent = GetAsDOMNode(pointToInsertBrNode.Container());
     *aInOutOffset = pointToInsertBrNode.Offset() + 1;
   } else {