Skip to content

Truly independent web browser

LibWeb: Collapse the caret after a newline from insertLineBreak

Andreas Kling788b00222615
diff --git a/Libraries/LibWeb/Editing/Commands.cpp b/Libraries/LibWeb/Editing/Commands.cpp
index 26e51c319fc..5b128d68f0c 100644
--- a/Libraries/LibWeb/Editing/Commands.cpp
+++ b/Libraries/LibWeb/Editing/Commands.cpp
@@ -1449,6 +1449,9 @@ bool command_insert_linebreak_action(DOM::Document& document, Utf16View)
MUST(selection.collapse(start_node->parent(), start_node->index() + 1));
auto br = MUST(DOM::create_element(document, HTML::TagNames::br, Namespace::HTML));
MUST(insert_node_into_range(*active_range(document), br));
+
+ // NB: Inserting the br made the selection span it. Collapse it again after the newline.
+ MUST(selection.collapse(start_node, text_node->length()));
}
return true;
}
@@ -1469,8 +1472,8 @@ bool command_insert_linebreak_action(DOM::Document& document, Utf16View)
if (!text->next_sibling()) {
auto br = MUST(DOM::create_element(document, HTML::TagNames::br, Namespace::HTML));
MUST(insert_node_into_range(*active_range(document), br));
- MUST(selection.collapse(text->parent(), text->index() + 1));
}
+ MUST(selection.collapse(text, 1));
return true;
}
}
diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre&command=insertText.txt b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre&command=insertText.txt
index 66d9a332347..3b117af405d 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre&command=insertText.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre&command=insertText.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 138 tests
-134 Pass
-4 Fail
+138 Pass
Pass <div contenteditable style="white-space:pre; display:block">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre; display:block">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre; display:block">a[]bc</div> (defaultParagraphSeparator: div)
@@ -30,7 +29,7 @@ Pass <div contenteditable><p style="display:block; white-space:pre">a[]bc</p></d
Pass <div contenteditable style="white-space:pre; display:inline">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre; display:inline">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre; display:inline">a[]bc</div> (defaultParagraphSeparator: div)
-Fail <div contenteditable style="white-space:pre; display:inline">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre; display:inline">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:inline"><div style="white-space:pre">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline"><div style="white-space:pre">[]abc</div></div> (defaultParagraphSeparator: div)
@@ -53,7 +52,7 @@ Pass <div contenteditable><p style="display:inline; white-space:pre">a[]bc</p></
Pass <div contenteditable style="white-space:pre; display:inline-block">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre; display:inline-block">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre; display:inline-block">a[]bc</div> (defaultParagraphSeparator: div)
-Fail <div contenteditable style="white-space:pre; display:inline-block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre; display:inline-block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:inline-block"><div style="white-space:pre">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline-block"><div style="white-space:pre">[]abc</div></div> (defaultParagraphSeparator: div)
@@ -99,7 +98,7 @@ Pass <div contenteditable><p style="display:block; white-space:pre">a[]bc</p></d
Pass <div contenteditable style="white-space:pre; display:inline">abc[]</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre; display:inline">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre; display:inline">a[]bc</div> (defaultParagraphSeparator: p)
-Fail <div contenteditable style="white-space:pre; display:inline">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre; display:inline">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:inline"><div style="white-space:pre">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline"><div style="white-space:pre">[]abc</div></div> (defaultParagraphSeparator: p)
@@ -122,7 +121,7 @@ Pass <div contenteditable><p style="display:inline; white-space:pre">a[]bc</p></
Pass <div contenteditable style="white-space:pre; display:inline-block">abc[]</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre; display:inline-block">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre; display:inline-block">a[]bc</div> (defaultParagraphSeparator: p)
-Fail <div contenteditable style="white-space:pre; display:inline-block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre; display:inline-block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:inline-block"><div style="white-space:pre">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline-block"><div style="white-space:pre">[]abc</div></div> (defaultParagraphSeparator: p)
diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-line&command=insertText.txt b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-line&command=insertText.txt
index 8dcd2a5ba43..96950976aa9 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-line&command=insertText.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-line&command=insertText.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 138 tests
-134 Pass
-4 Fail
+138 Pass
Pass <div contenteditable style="white-space:pre-line; display:block">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-line; display:block">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-line; display:block">a[]bc</div> (defaultParagraphSeparator: div)
@@ -30,7 +29,7 @@ Pass <div contenteditable><p style="display:block; white-space:pre-line">a[]bc</
Pass <div contenteditable style="white-space:pre-line; display:inline">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-line; display:inline">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-line; display:inline">a[]bc</div> (defaultParagraphSeparator: div)
-Fail <div contenteditable style="white-space:pre-line; display:inline">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre-line; display:inline">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre-line; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:inline"><div style="white-space:pre-line">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline"><div style="white-space:pre-line">[]abc</div></div> (defaultParagraphSeparator: div)
@@ -53,7 +52,7 @@ Pass <div contenteditable><p style="display:inline; white-space:pre-line">a[]bc<
Pass <div contenteditable style="white-space:pre-line; display:inline-block">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-line; display:inline-block">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-line; display:inline-block">a[]bc</div> (defaultParagraphSeparator: div)
-Fail <div contenteditable style="white-space:pre-line; display:inline-block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre-line; display:inline-block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre-line; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:inline-block"><div style="white-space:pre-line">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline-block"><div style="white-space:pre-line">[]abc</div></div> (defaultParagraphSeparator: div)
@@ -99,7 +98,7 @@ Pass <div contenteditable><p style="display:block; white-space:pre-line">a[]bc</
Pass <div contenteditable style="white-space:pre-line; display:inline">abc[]</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre-line; display:inline">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre-line; display:inline">a[]bc</div> (defaultParagraphSeparator: p)
-Fail <div contenteditable style="white-space:pre-line; display:inline">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre-line; display:inline">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre-line; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:inline"><div style="white-space:pre-line">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline"><div style="white-space:pre-line">[]abc</div></div> (defaultParagraphSeparator: p)
@@ -122,7 +121,7 @@ Pass <div contenteditable><p style="display:inline; white-space:pre-line">a[]bc<
Pass <div contenteditable style="white-space:pre-line; display:inline-block">abc[]</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre-line; display:inline-block">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre-line; display:inline-block">a[]bc</div> (defaultParagraphSeparator: p)
-Fail <div contenteditable style="white-space:pre-line; display:inline-block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre-line; display:inline-block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre-line; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:inline-block"><div style="white-space:pre-line">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline-block"><div style="white-space:pre-line">[]abc</div></div> (defaultParagraphSeparator: p)
diff --git a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-wrap&command=insertText.txt b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-wrap&command=insertText.txt
index d9a20e2a6bb..77c1a5636bb 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-wrap&command=insertText.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/editing/other/insertparagraph-with-white-space-style.tentative@white-space=pre-wrap&command=insertText.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 138 tests
-134 Pass
-4 Fail
+138 Pass
Pass <div contenteditable style="white-space:pre-wrap; display:block">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-wrap; display:block">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-wrap; display:block">a[]bc</div> (defaultParagraphSeparator: div)
@@ -30,7 +29,7 @@ Pass <div contenteditable><p style="display:block; white-space:pre-wrap">a[]bc</
Pass <div contenteditable style="white-space:pre-wrap; display:inline">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-wrap; display:inline">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-wrap; display:inline">a[]bc</div> (defaultParagraphSeparator: div)
-Fail <div contenteditable style="white-space:pre-wrap; display:inline">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre-wrap; display:inline">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre-wrap; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:inline"><div style="white-space:pre-wrap">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline"><div style="white-space:pre-wrap">[]abc</div></div> (defaultParagraphSeparator: div)
@@ -53,7 +52,7 @@ Pass <div contenteditable><p style="display:inline; white-space:pre-wrap">a[]bc<
Pass <div contenteditable style="white-space:pre-wrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-wrap; display:inline-block">[]abc</div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="white-space:pre-wrap; display:inline-block">a[]bc</div> (defaultParagraphSeparator: div)
-Fail <div contenteditable style="white-space:pre-wrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre-wrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: div) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre-wrap; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: div) (preserving inline style test)
Pass <div contenteditable style="display:inline-block"><div style="white-space:pre-wrap">abc[]</div></div> (defaultParagraphSeparator: div)
Pass <div contenteditable style="display:inline-block"><div style="white-space:pre-wrap">[]abc</div></div> (defaultParagraphSeparator: div)
@@ -99,7 +98,7 @@ Pass <div contenteditable><p style="display:block; white-space:pre-wrap">a[]bc</
Pass <div contenteditable style="white-space:pre-wrap; display:inline">abc[]</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre-wrap; display:inline">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre-wrap; display:inline">a[]bc</div> (defaultParagraphSeparator: p)
-Fail <div contenteditable style="white-space:pre-wrap; display:inline">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre-wrap; display:inline">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre-wrap; display:inline"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:inline"><div style="white-space:pre-wrap">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline"><div style="white-space:pre-wrap">[]abc</div></div> (defaultParagraphSeparator: p)
@@ -122,7 +121,7 @@ Pass <div contenteditable><p style="display:inline; white-space:pre-wrap">a[]bc<
Pass <div contenteditable style="white-space:pre-wrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre-wrap; display:inline-block">[]abc</div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="white-space:pre-wrap; display:inline-block">a[]bc</div> (defaultParagraphSeparator: p)
-Fail <div contenteditable style="white-space:pre-wrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
+Pass <div contenteditable style="white-space:pre-wrap; display:inline-block">abc[]</div> (defaultParagraphSeparator: p) (preserving temporary inline style test)
Pass <div contenteditable style="white-space:pre-wrap; display:inline-block"><b>abc[]</b></div> (defaultParagraphSeparator: p) (preserving inline style test)
Pass <div contenteditable style="display:inline-block"><div style="white-space:pre-wrap">abc[]</div></div> (defaultParagraphSeparator: p)
Pass <div contenteditable style="display:inline-block"><div style="white-space:pre-wrap">[]abc</div></div> (defaultParagraphSeparator: p)