diff --git a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp index 278b6c0a91b..48abcb2d721 100644 --- a/Libraries/LibWeb/Editing/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/Editing/Internal/Algorithms.cpp @@ -1981,15 +1981,10 @@ bool is_collapsed_line_break(GC::Ref node) return false; // that begins a line box which has nothing else in it, and therefore has zero height. - auto layout_node = node->layout_node(); - if (!layout_node) - return false; - VERIFY(is(*layout_node)); - - // NOTE: We do not generate a TextNode for empty text after the break, so if we do not have a sibling or if that - // sibling is not a TextNode, we consider it a collapsed line break. - auto* next_layout_node = layout_node->next_sibling(); - return !is(next_layout_node); + // NOTE: We check this on the DOM-level by seeing if the next node is neither a non-empty text node nor a
. + if (auto text_node = as_if(node->next_sibling())) + return text_node->text_content().value_or({}).is_empty(); + return !is(node->next_sibling()); } // https://w3c.github.io/editing/docs/execCommand/#collapsed-whitespace-node diff --git a/Tests/LibWeb/Text/expected/Editing/execCommand-insertLinebreak.txt b/Tests/LibWeb/Text/expected/Editing/execCommand-insertLinebreak.txt index 1ec240902d4..c0d5e6103ff 100644 --- a/Tests/LibWeb/Text/expected/Editing/execCommand-insertLinebreak.txt +++ b/Tests/LibWeb/Text/expected/Editing/execCommand-insertLinebreak.txt @@ -7,3 +7,5 @@ Before: "

foobar

" After: "

foobar

" +Before: "foo" +After: "foo

" diff --git a/Tests/LibWeb/Text/input/Editing/execCommand-insertLinebreak.html b/Tests/LibWeb/Text/input/Editing/execCommand-insertLinebreak.html index 398f1abbee1..4b4578870f8 100644 --- a/Tests/LibWeb/Text/input/Editing/execCommand-insertLinebreak.html +++ b/Tests/LibWeb/Text/input/Editing/execCommand-insertLinebreak.html @@ -3,11 +3,13 @@
foobar

foobar

foobar

+
foo