Truly independent web browser
LibWeb: Keep paragraph split boundaries inside their container
Andreas Kling5090719f8d6c
diff --git a/Libraries/LibWeb/Editing/Commands.cpp b/Libraries/LibWeb/Editing/Commands.cppindex 9a463579d14..5b098325b0c 100644--- a/Libraries/LibWeb/Editing/Commands.cpp+++ b/Libraries/LibWeb/Editing/Commands.cpp@@ -2157,7 +2157,9 @@ bool command_insert_paragraph_action(DOM::Document& document, Utf16View)// 15. While new line range's start offset is zero and its start node is not a prohibited paragraph child, set its// start to (parent of start node, index of start node).GC::Ptr<DOM::Node> start_container = new_line_range->start_container();- while (start_container->parent() && new_line_range->start_offset() == 0 && !is_prohibited_paragraph_child(*start_container)) {+ // INTEROP: Keep the split boundary inside the paragraph container, so that the caret at the end of e.g. a flex or+ // grid item does not move the new paragraph outside of it.+ while (start_container != container && start_container->parent() && new_line_range->start_offset() == 0 && !is_prohibited_paragraph_child(*start_container)) {MUST(new_line_range->set_start(*start_container->parent(), start_container->index()));start_container = start_container->parent();}@@ -2165,7 +2167,7 @@ bool command_insert_paragraph_action(DOM::Document& document, Utf16View)// 16. While new line range's start offset is the length of its start node and its start node is not a prohibited// paragraph child, set its start to (parent of start node, 1 + index of start node).start_container = new_line_range->start_container();- while (start_container->parent() && new_line_range->start_offset() == start_container->length()+ while (start_container != container && start_container->parent() && new_line_range->start_offset() == start_container->length()&& !is_prohibited_paragraph_child(*start_container)) {MUST(new_line_range->set_start(*start_container->parent(), start_container->index() + 1));start_container = start_container->parent();diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/run/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/editing/run/[email protected]index a625cf64178..dc13b77fdaf 100644--- a/Tests/LibWeb/Text/expected/wpt-import/editing/run/[email protected]+++ b/Tests/LibWeb/Text/expected/wpt-import/editing/run/[email protected]@@ -2,8 +2,8 @@ Harness status: OKFound 195 tests-184 Pass-11 Fail+192 Pass+3 FailPass [["defaultparagraphseparator","div"],["insertparagraph",""]] "foo<br>[]bar<br><span>baz</span>": execCommand("insertparagraph", false, "") return valuePass [["defaultparagraphseparator","div"],["insertparagraph",""]] "foo<br>[]bar<br><span>baz</span>" checks for modifications to non-editable contentPass [["defaultparagraphseparator","div"],["insertparagraph",""]] "foo<br>[]bar<br><span>baz</span>" compare innerHTML@@ -106,19 +106,19 @@ Pass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=dispPass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:flex><span>abc[]</span></div>": execCommand("defaultparagraphseparator", false, "div") return valuePass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:flex><span>abc[]</span></div>": execCommand("insertparagraph", false, "") return valuePass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:flex><span>abc[]</span></div>" checks for modifications to non-editable content-Fail [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:flex><span>abc[]</span></div>" compare innerHTML+Pass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:flex><span>abc[]</span></div>" compare innerHTMLPass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:flex><span>abc[]</span></div>": execCommand("defaultparagraphseparator", false, "p") return valuePass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:flex><span>abc[]</span></div>": execCommand("insertparagraph", false, "") return valuePass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:flex><span>abc[]</span></div>" checks for modifications to non-editable content-Fail [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:flex><span>abc[]</span></div>" compare innerHTML+Pass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:flex><span>abc[]</span></div>" compare innerHTMLPass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:inline-flex><span>abc[]</span></div>": execCommand("defaultparagraphseparator", false, "div") return valuePass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:inline-flex><span>abc[]</span></div>": execCommand("insertparagraph", false, "") return valuePass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:inline-flex><span>abc[]</span></div>" checks for modifications to non-editable content-Fail [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:inline-flex><span>abc[]</span></div>" compare innerHTML+Pass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:inline-flex><span>abc[]</span></div>" compare innerHTMLPass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:inline-flex><span>abc[]</span></div>": execCommand("defaultparagraphseparator", false, "p") return valuePass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:inline-flex><span>abc[]</span></div>": execCommand("insertparagraph", false, "") return valuePass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:inline-flex><span>abc[]</span></div>" checks for modifications to non-editable content-Fail [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:inline-flex><span>abc[]</span></div>" compare innerHTML+Pass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:inline-flex><span>abc[]</span></div>" compare innerHTMLPass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:grid><span>[]abc</span></div>": execCommand("defaultparagraphseparator", false, "div") return valuePass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:grid><span>[]abc</span></div>": execCommand("insertparagraph", false, "") return valuePass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:grid><span>[]abc</span></div>" checks for modifications to non-editable content@@ -154,19 +154,19 @@ Pass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=dispPass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:grid><span>abc[]</span></div>": execCommand("defaultparagraphseparator", false, "div") return valuePass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:grid><span>abc[]</span></div>": execCommand("insertparagraph", false, "") return valuePass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:grid><span>abc[]</span></div>" checks for modifications to non-editable content-Fail [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:grid><span>abc[]</span></div>" compare innerHTML+Pass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:grid><span>abc[]</span></div>" compare innerHTMLPass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:grid><span>abc[]</span></div>": execCommand("defaultparagraphseparator", false, "p") return valuePass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:grid><span>abc[]</span></div>": execCommand("insertparagraph", false, "") return valuePass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:grid><span>abc[]</span></div>" checks for modifications to non-editable content-Fail [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:grid><span>abc[]</span></div>" compare innerHTML+Pass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:grid><span>abc[]</span></div>" compare innerHTMLPass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:inline-grid><span>abc[]</span></div>": execCommand("defaultparagraphseparator", false, "div") return valuePass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:inline-grid><span>abc[]</span></div>": execCommand("insertparagraph", false, "") return valuePass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:inline-grid><span>abc[]</span></div>" checks for modifications to non-editable content-Fail [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:inline-grid><span>abc[]</span></div>" compare innerHTML+Pass [["defaultparagraphseparator","div"],["insertparagraph",""]] "<div style=display:inline-grid><span>abc[]</span></div>" compare innerHTMLPass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:inline-grid><span>abc[]</span></div>": execCommand("defaultparagraphseparator", false, "p") return valuePass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:inline-grid><span>abc[]</span></div>": execCommand("insertparagraph", false, "") return valuePass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:inline-grid><span>abc[]</span></div>" checks for modifications to non-editable content-Fail [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:inline-grid><span>abc[]</span></div>" compare innerHTML+Pass [["defaultparagraphseparator","p"],["insertparagraph",""]] "<div style=display:inline-grid><span>abc[]</span></div>" compare innerHTMLPass [["defaultparagraphseparator","div"],["insertparagraph",""]] " <span contenteditable=\"false\">A</span>[] ; <span contenteditable=\"false\">B</span> ; <span contenteditable=\"false\">C</span> ": execCommand("defaultparagraphseparator", false, "div") return valuePass [["defaultparagraphseparator","div"],["insertparagraph",""]] " <span contenteditable=\"false\">A</span>[] ; <span contenteditable=\"false\">B</span> ; <span contenteditable=\"false\">C</span> ": execCommand("insertparagraph", false, "") return valuePass [["defaultparagraphseparator","div"],["insertparagraph",""]] " <span contenteditable=\"false\">A</span>[] ; <span contenteditable=\"false\">B</span> ; <span contenteditable=\"false\">C</span> " checks for modifications to non-editable content