Bug 1582215 - Make `HTMLEditor::DoInsertHTMLWithContext()` compute new insertion point before removing unnecessary `<li>` elements r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 17 Oct 2019 09:17:14 +0000
changeset 559310 c5e7322c11b43c63acedd5b324f7c5468b317e72
parent 559309 883bbf87a11027b6513187654160bf73be5a1e11
child 559311 cbafd2e6cf53e85f9c8d25f3b1f10f98c53744f2
push id12177
push usercsabou@mozilla.com
push dateMon, 21 Oct 2019 14:52:16 +0000
treeherdermozilla-beta@1918a9cd33bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1582215
milestone71.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1582215 - Make `HTMLEditor::DoInsertHTMLWithContext()` compute new insertion point before removing unnecessary `<li>` elements r=m_kato When inserting `<li>` elements into `<ul>`, `<ol>` or `<li>` element, `HTMLEditor::DoInsertHTMLWithContext()` removes unnecessary empty `<li>` elements at insertion point. At this time, we've computed next insertion point with removed `<li>` element. Therefore, insertion point goes out from the DOM tree. This patch makes it compute new insertion point before removing each empty `<li>` element. Additionally, this patch adds some WPT data for testing this case. I verified that Chrome passes the new tests too. Differential Revision: https://phabricator.services.mozilla.com/D49394
editor/libeditor/HTMLEditorDataTransfer.cpp
testing/web-platform/tests/editing/data/inserthtml.js
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -490,19 +490,20 @@ nsresult HTMLEditor::DoInsertHTMLWithCon
           if (HTMLEditUtils::IsListItem(pointToInsert.GetContainer())) {
             bool isEmpty;
             rv = IsEmptyNode(pointToInsert.GetContainer(), &isEmpty, true);
             if (NS_SUCCEEDED(rv) && isEmpty) {
               NS_WARNING_ASSERTION(
                   pointToInsert.GetContainer()->GetParentNode(),
                   "Insertion point is out of the DOM tree");
               if (pointToInsert.GetContainer()->GetParentNode()) {
+                pointToInsert.Set(pointToInsert.GetContainer());
+                AutoEditorDOMPointChildInvalidator lockOffset(pointToInsert);
                 DeleteNodeWithTransaction(
-                    MOZ_KnownLive(*pointToInsert.GetContainer()));
-                pointToInsert.Set(pointToInsert.GetContainer());
+                    MOZ_KnownLive(*pointToInsert.GetChild()));
               }
             }
           }
           EditorDOMPoint insertedPoint =
               InsertNodeIntoProperAncestorWithTransaction(
                   *firstChild, pointToInsert,
                   SplitAtEdges::eDoNotCreateEmptyContainer);
           if (NS_WARN_IF(!insertedPoint.IsSet())) {
--- a/testing/web-platform/tests/editing/data/inserthtml.js
+++ b/testing/web-platform/tests/editing/data/inserthtml.js
@@ -355,16 +355,36 @@ var browserTests = [
     "<ol><li>f<ul><li>abc</li></ul>{}o</li></ol>",
     [true],
     {"inserthtml":[false,false,"",false,false,""]}],
 ["<ul><li>f[o]o</ul>",
     [["inserthtml","<ul><li>abc</ul>"]],
     "<ul><li>f<ul><li>abc</li></ul>{}o</li></ul>",
     [true],
     {"inserthtml":[false,false,"",false,false,""]}],
+["<ul id=\"old\"><li id=\"li0\">{}<br></ul>",
+    [["inserthtml","<ul id=\"new\"><li id=\"li1\">abc</li><li id=\"li2\">def</li></ul>"]],
+    "<ul id=\"old\"><li id=\"li1\">abc</li><li id=\"li2\">def</li></ul>",
+    [true],
+    {"inserthtml":[false,false,"",false,false,""]}],
+["<ol id=\"old\"><li id=\"li0\">{}<br></ol>",
+    [["inserthtml","<ol id=\"new\"><li id=\"li1\">abc</li><li id=\"li2\">def</li></ol>"]],
+    "<ol id=\"old\"><li id=\"li1\">abc</li><li id=\"li2\">def</li></ol>",
+    [true],
+    {"inserthtml":[false,false,"",false,false,""]}],
+["<ul id=\"old\"><li id=\"li0\">{}<br></ul>",
+    [["inserthtml","<ol id=\"new\"><li id=\"li1\">abc</li><li id=\"li2\">def</li></ol>"]],
+    "<ul id=\"old\"><li id=\"li1\">abc</li><li id=\"li2\">def</li></ul>",
+    [true],
+    {"inserthtml":[false,false,"",false,false,""]}],
+["<ol id=\"old\"><li id=\"li0\">{}<br></ol>",
+    [["inserthtml","<ul id=\"new\"><li id=\"li1\">abc</li><li id=\"li2\">def</li></ul>"]],
+    "<ol id=\"old\"><li id=\"li1\">abc</li><li id=\"li2\">def</li></ol>",
+    [true],
+    {"inserthtml":[false,false,"",false,false,""]}],
 ["f[o]o",
     [["defaultparagraphseparator","div"],["inserthtml","<li>abc</li>"]],
     "f<div>abc</div>{}o",
     [true,true],
     {"defaultparagraphseparator":[false,false,"p",false,false,"div"],"inserthtml":[false,false,"",false,false,""]}],
 ["f[o]o",
     [["defaultparagraphseparator","p"],["inserthtml","<li>abc</li>"]],
     "f<p>abc</p>{}o",