Bug 1420415 - TextEditor::CreateBRImpl() needs to make pointToInsertBrNode store mOffset before calling EditorBase::CreateNode() r=m_kato a=gchang
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 24 Nov 2017 23:17:38 +0900
changeset 445016 3e16c8e2364ba5655325e2c4fa3df329db7a339b
parent 445015 9c16e62a2f500015f0c5309ac45db22533cb0bad
child 445017 a9ce90a8eeabc58651c4e39c6a16be095865ac90
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato, gchang
bugs1420415, 1408227
milestone58.0
Bug 1420415 - TextEditor::CreateBRImpl() needs to make pointToInsertBrNode store mOffset before calling EditorBase::CreateNode() r=m_kato a=gchang 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
@@ -458,16 +458,19 @@ TextEditor::CreateBRImpl(nsCOMPtr<nsIDOM
       ErrorResult rv;
       SplitNode(*node->AsContent(), theOffset, rv);
       if (NS_WARN_IF(rv.Failed())) {
         return rv.StealNSResult();
       }
       atNode.Clear();
       atNode.Set(node);
     }
+    // Lock the offset of atNode because it'll be referred after
+    // inserting a new <br> node before it.
+    Unused << atNode.Offset();
     // create br
     brNode = CreateNode(nsGkAtoms::br, atNode);
     if (NS_WARN_IF(!brNode)) {
       return NS_ERROR_FAILURE;
     }
     *aInOutParent = GetAsDOMNode(atNode.Container());
     *aInOutOffset = atNode.Offset() + 1;
   } else {