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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-10-17 09:17:14 +00:00
Родитель 97dc13cb94
Коммит abdf9727f5
2 изменённых файлов: 23 добавлений и 2 удалений

Просмотреть файл

@ -495,9 +495,10 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
pointToInsert.GetContainer()->GetParentNode(),
"Insertion point is out of the DOM tree");
if (pointToInsert.GetContainer()->GetParentNode()) {
DeleteNodeWithTransaction(
MOZ_KnownLive(*pointToInsert.GetContainer()));
pointToInsert.Set(pointToInsert.GetContainer());
AutoEditorDOMPointChildInvalidator lockOffset(pointToInsert);
DeleteNodeWithTransaction(
MOZ_KnownLive(*pointToInsert.GetChild()));
}
}
}

Просмотреть файл

@ -360,6 +360,26 @@ var browserTests = [
"<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",