Truly independent web browser
LibWeb: Do not delete the body element in an editable html element
Andreas Kling7543ec9ddca4
diff --git a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp b/Libraries/LibWeb/Editing/Internal/Algorithms.cppindex fef5a3bb49d..06a65b68763 100644--- a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp+++ b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp@@ -38,9 +38,11 @@#include <LibWeb/HTML/FormAssociatedElement.h>#include <LibWeb/HTML/HTMLAnchorElement.h>#include <LibWeb/HTML/HTMLBRElement.h>+#include <LibWeb/HTML/HTMLBodyElement.h>#include <LibWeb/HTML/HTMLDivElement.h>#include <LibWeb/HTML/HTMLElement.h>#include <LibWeb/HTML/HTMLFontElement.h>+#include <LibWeb/HTML/HTMLHeadElement.h>#include <LibWeb/HTML/HTMLImageElement.h>#include <LibWeb/HTML/HTMLLIElement.h>#include <LibWeb/HTML/HTMLOListElement.h>@@ -1313,6 +1315,11 @@ void delete_the_selection(Selection& selection, bool block_merging, bool strip_wif (!node->is_editable())return IterationDecision::Continue;+ // INTEROP: Browsers do not delete the body or the head element, or the content of the head element, in an+ // editable html element. They delete the children of the body element instead.+ if (is<HTML::HTMLBodyElement>(*node) || node->first_ancestor_of_type<HTML::HTMLHeadElement>() || is<HTML::HTMLHeadElement>(*node))+ return IterationDecision::Continue;+if (!is<HTML::HTMLTableSectionElement>(*node) && !is<HTML::HTMLTableRowElement>(*node) && !is<HTML::HTMLTableCellElement>(*node))node_list.append(node);diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/other/select-all-and-delete-in-html-element-having-contenteditable.txt b/Tests/LibWeb/Text/expected/wpt-import/editing/other/select-all-and-delete-in-html-element-having-contenteditable.txtindex 0d16a5bff06..d84cbedf73e 100644--- a/Tests/LibWeb/Text/expected/wpt-import/editing/other/select-all-and-delete-in-html-element-having-contenteditable.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/editing/other/select-all-and-delete-in-html-element-having-contenteditable.txt@@ -2,17 +2,16 @@ Harness status: OKFound 12 tests-2 Pass-10 Fail-Fail Select All, then, Backspace-Fail Select All, then, Delete-Fail execCommand("selectall"), then, Backspace-Fail execCommand("selectall"), then, Delete-Fail Select All, then, execCommand("forwarddelete")-Fail Select All, then, execCommand("delete")+12 Pass+Pass Select All, then, Backspace+Pass Select All, then, Delete+Pass execCommand("selectall"), then, Backspace+Pass execCommand("selectall"), then, Delete+Pass Select All, then, execCommand("forwarddelete")+Pass Select All, then, execCommand("delete")Pass execCommand("selectall"), then, execCommand("forwarddelete")Pass execCommand("selectall"), then, execCommand("delete")-Fail getSelection().selectAllChildren(document.documentElement), then, Backspace-Fail getSelection().selectAllChildren(document.documentElement), then, Delete-Fail getSelection().selectAllChildren(document.documentElement), then, execCommand("forwarddelete")-Fail getSelection().selectAllChildren(document.documentElement), then, execCommand("delete")\ No newline at end of file+Pass getSelection().selectAllChildren(document.documentElement), then, Backspace+Pass getSelection().selectAllChildren(document.documentElement), then, Delete+Pass getSelection().selectAllChildren(document.documentElement), then, execCommand("forwarddelete")+Pass getSelection().selectAllChildren(document.documentElement), then, execCommand("delete")\ No newline at end of file