Skip to content

Truly independent web browser

LibWeb: Insert the extra br after the new br in insertLineBreak

Andreas Kling0479947e4521
diff --git a/Libraries/LibWeb/Editing/Commands.cpp b/Libraries/LibWeb/Editing/Commands.cpp
index f6e91757bc3..21b14113ab4 100644
--- a/Libraries/LibWeb/Editing/Commands.cpp
+++ b/Libraries/LibWeb/Editing/Commands.cpp
@@ -1490,7 +1490,7 @@ bool command_insert_linebreak_action(DOM::Document& document, Utf16View)
// result, then call insertNode(extra br) on the active range.
if (is_collapsed_line_break(br)) {
auto extra_br = MUST(DOM::create_element(document, HTML::TagNames::br, Namespace::HTML));
- MUST(insert_node_into_range(range, extra_br));
+ MUST(insert_node_into_range(*active_range(document), extra_br));
// INTEROP: The range insertion leaves the range spanning extra br; Chromium keeps the caret collapsed
// between the two line breaks.
diff --git a/Tests/LibWeb/Text/expected/Editing/insertLinebreak-collapsed-break-caret.txt b/Tests/LibWeb/Text/expected/Editing/insertLinebreak-collapsed-break-caret.txt
index 4a9c2e36207..0dc53fc7bbe 100644
--- a/Tests/LibWeb/Text/expected/Editing/insertLinebreak-collapsed-break-caret.txt
+++ b/Tests/LibWeb/Text/expected/Editing/insertLinebreak-collapsed-break-caret.txt
@@ -1,4 +1,4 @@
-at end of text: "hello<br><br>" sel=#text@5
+at end of text: "hello<br><br>" sel=host@2
at end of text after undo: "hello"
-in empty host: "<br><br>" sel=host@0
+in empty host: "<br><br>" sel=host@1
in empty host after undo: ""
diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=nowrap&command=insertParagraph.txt b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=nowrap&command=insertParagraph.txt
index cb30d07a0ff..274d42b6a8f 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=nowrap&command=insertParagraph.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=nowrap&command=insertParagraph.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 138 tests
-104 Pass
-34 Fail
+112 Pass
+26 Fail
Pass <div contenteditable style="white-space:nowrap; display:block">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:block">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:block">a[]bc</div> (defaultParagraphSeparator: div)
@@ -30,8 +30,8 @@ Pass <div contenteditable><p style="display:block; white-space:nowrap">a[]bc</p>
Pass <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:inline">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:inline">a[]bc</div> (defaultParagraphSeparator: div)
-Fail <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
-Fail <div contenteditable style="white-space:nowrap; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">[]abc</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">a[]bc</div></div> (defaultParagraphSeparator: div)
@@ -53,8 +53,8 @@ Fail <div contenteditable><p style="display:inline; white-space:nowrap">a[]bc</p
Pass <div contenteditable style="white-space:nowrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:inline-block">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:inline-block">a[]bc</div> (defaultParagraphSeparator: div)
-Fail <div contenteditable style="white-space:nowrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
-Fail <div contenteditable style="white-space:nowrap; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">[]abc</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">a[]bc</div></div> (defaultParagraphSeparator: div)
@@ -99,8 +99,8 @@ Pass <div contenteditable><p style="display:block; white-space:nowrap">a[]bc</p>
Pass <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:nowrap; display:inline">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:nowrap; display:inline">a[]bc</div> (defaultParagraphSeparator: p)
-Fail <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
-Fail <div contenteditable style="white-space:nowrap; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">[]abc</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">a[]bc</div></div> (defaultParagraphSeparator: p)
@@ -122,8 +122,8 @@ Fail <div contenteditable><p style="display:inline; white-space:nowrap">a[]bc</p
Pass <div contenteditable style="white-space:nowrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:nowrap; display:inline-block">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:nowrap; display:inline-block">a[]bc</div> (defaultParagraphSeparator: p)
-Fail <div contenteditable style="white-space:nowrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
-Fail <div contenteditable style="white-space:nowrap; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">[]abc</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">a[]bc</div></div> (defaultParagraphSeparator: p)
diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=nowrap&command=insertText.txt b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=nowrap&command=insertText.txt
index 0d82a0c60db..68b7bdbae7c 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=nowrap&command=insertText.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=nowrap&command=insertText.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 138 tests
-102 Pass
-36 Fail
+106 Pass
+32 Fail
Pass <div contenteditable style="white-space:nowrap; display:block">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:block">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:block">a[]bc</div> (defaultParagraphSeparator: div)
@@ -31,7 +31,7 @@ Pass <div contenteditable style="white-space:nowrap; display:inline">abc[]</div>
Pass <div contenteditable style="white-space:nowrap; display:inline">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:inline">a[]bc</div> (defaultParagraphSeparator: div)
Fail <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
-Fail <div contenteditable style="white-space:nowrap; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">[]abc</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">a[]bc</div></div> (defaultParagraphSeparator: div)
@@ -54,7 +54,7 @@ Pass <div contenteditable style="white-space:nowrap; display:inline-block">abc[]
Pass <div contenteditable style="white-space:nowrap; display:inline-block">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:nowrap; display:inline-block">a[]bc</div> (defaultParagraphSeparator: div)
Fail <div contenteditable style="white-space:nowrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
-Fail <div contenteditable style="white-space:nowrap; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">[]abc</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">a[]bc</div></div> (defaultParagraphSeparator: div)
@@ -100,7 +100,7 @@ Pass <div contenteditable style="white-space:nowrap; display:inline">abc[]</div>
Pass <div contenteditable style="white-space:nowrap; display:inline">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:nowrap; display:inline">a[]bc</div> (defaultParagraphSeparator: p)
Fail <div contenteditable style="white-space:nowrap; display:inline">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
-Fail <div contenteditable style="white-space:nowrap; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">[]abc</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline"><div style="white-space:nowrap">a[]bc</div></div> (defaultParagraphSeparator: p)
@@ -123,7 +123,7 @@ Pass <div contenteditable style="white-space:nowrap; display:inline-block">abc[]
Pass <div contenteditable style="white-space:nowrap; display:inline-block">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:nowrap; display:inline-block">a[]bc</div> (defaultParagraphSeparator: p)
Fail <div contenteditable style="white-space:nowrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
-Fail <div contenteditable style="white-space:nowrap; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
+Pass <div contenteditable style="white-space:nowrap; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">[]abc</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline-block"><div style="white-space:nowrap">a[]bc</div></div> (defaultParagraphSeparator: p)