forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1828078 - part 1: Make
HTMLEditUtils::CanNodeContain
handle com…
…ment node r=m_kato `HTMLEditUtils::CanNodeContain` does not handle comment nodes and cdata section nodes (the latter one is available only in XHTML documents, it's treated as a comment node in HTML documents). When copying HTML from Word on Windows, that contains 2 comment nodes at start of pasting body (which does not appear in clipboard viewer, so, Gecko creates them somewhere) and that causes `HTMLEditUtils::CanNodeContain` returns `false` for any parents. Therefore, `HTMLEditor::InsertNodeIntoProperAncestorWithTransaction` returns error and the pasting fails with odd state and unexpectedly split the list item in `HTMLWithContextInserter::InsertContents`. Finally, undoing fails to do some of them and causes destroying the editable nodes. This patch makes `HTMLEditUtils::CanNodeContain` work with comment nodes and cdata section nodes (the latter is treated as a comment node since there is no "cdata" tag definition of `nsHTMLTag`) and `HTMLEditor::InsertNodeIntoProperAncestorWithTransaction` just return "not handled" result for some other types of nodes which cannot be inserted in any elements. Note that the result of pasting from Word is different from Chrome's result. Chrome does not paste such comment nodes (but inserts comment nodes with `insertHTML` command). For now, I don't want to work on fixing this compatibility issue since comment nodes does not cause any known troubles. Therefore, this patch does not contain WPT updates. Differential Revision: https://phabricator.services.mozilla.com/D176766
- Loading branch information
1 parent
b758499
commit 95e22b6
Showing
5 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
editor/libeditor/tests/test_insertHTML_starting_with_multiple_comment_nodes.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Insert HTML containing comment nodes</title> | ||
<script src="/tests/SimpleTest/SimpleTest.js"></script> | ||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> | ||
<script> | ||
"use strict"; | ||
|
||
SimpleTest.waitForExplicitFinish(); | ||
SimpleTest.waitForFocus(() => { | ||
const editor = document.querySelector("div[contenteditable]"); | ||
getSelection().collapse(editor.querySelector("li").firstChild, 1); | ||
document.execCommand("insertHTML", false, "<!-- 1 --><!-- 2 -->b"); | ||
is( | ||
editor.innerHTML, | ||
"<ul><li>a<!-- 1 --><!-- 2 -->bc</li></ul>", | ||
"The HTML fragment should be inserted as-is" | ||
); | ||
document.execCommand("undo"); | ||
is( | ||
editor.innerHTML, | ||
"<ul><li>ac</li></ul>", | ||
"Undoing should work as expected" | ||
); | ||
document.execCommand("redo"); | ||
is( | ||
editor.innerHTML, | ||
"<ul><li>a<!-- 1 --><!-- 2 -->bc</li></ul>", | ||
"Redoing should work as expected" | ||
); | ||
SimpleTest.finish(); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<div contenteditable><ul><li>ac</li></ul></div> | ||
</body> | ||
</html> |