Bug 1749299 - Make `HTMLEditor::HandleInsertLinefeed()` stop handling it if insertion point cannot have text nodes r=m_kato

Ideally, it should not be called when the editor cannot insert new text node.
However, the callers are complicated.  Therefore, let's check in it for avoiding
making the callers more complicated.  Fortunately, this is not realistic path
for normal web apps.  Therefore, the compatibility of the behavior is not
matter.  That's the reason why this patch does not have a test comparing the
result.

Differential Revision: https://phabricator.services.mozilla.com/D135826
This commit is contained in:
Masayuki Nakano 2022-01-16 06:21:17 +00:00
Родитель 4b13ebc817
Коммит 72c7cef167
3 изменённых файлов: 36 добавлений и 4 удалений

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

@ -2000,10 +2000,18 @@ nsresult HTMLEditor::HandleInsertLinefeed(const EditorDOMPoint& aPointToBreak,
return NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE;
}
MOZ_ASSERT(pointToInsert.IsSetAndValid());
MOZ_ASSERT_IF(
!pointToInsert.IsInTextNode(),
HTMLEditUtils::CanNodeContain(*pointToInsert.ContainerAsContent(),
*nsGkAtoms::textTagName));
// The node may not be able to have a text node so that we need to check it
// here.
if (!pointToInsert.IsInTextNode() &&
!HTMLEditUtils::CanNodeContain(*pointToInsert.ContainerAsContent(),
*nsGkAtoms::textTagName)) {
NS_WARNING(
"HTMLEditor::HandleInsertLinefeed() couldn't insert a linefeed because "
"the insertion position couldn't have text nodes");
return NS_ERROR_EDITOR_NO_EDITABLE_RANGE;
}
RefPtr<Document> document = GetDocument();
MOZ_ASSERT(document);
if (NS_WARN_IF(!document)) {

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

@ -0,0 +1,12 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script>
document.addEventListener("DOMContentLoaded", () => {
document.getElementById("id_0").contentEditable = false;
document.querySelector("[contenteditable]").focus();
document.execCommand("insertLineBreak");
})
</script>
<pre>
<ins id="id_0">
<map contenteditable>

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

@ -0,0 +1,12 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script>
document.addEventListener("DOMContentLoaded", () => {
document.getElementById("id_0").contentEditable = false;
document.querySelector("[contenteditable]").focus();
document.execCommand("insertParagraph");
})
</script>
<pre>
<ins id="id_0">
<map contenteditable>