1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

LibWeb: Swallow whitespace when it causes us to break the line

This fixes an issue seen on Acid3 where the instruction text would shift
around when moving from "white-space:pre-wrap" to "white-space:normal".
This commit is contained in:
Andreas Kling 2022-03-29 13:35:21 +02:00
parent 02e97b3313
commit f4ed4b2806

View file

@ -253,8 +253,17 @@ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode)
case InlineLevelIterator::Item::Type::Text: {
auto& text_node = verify_cast<Layout::TextNode>(*item.node);
if (line_builder.break_if_needed(layout_mode, item.border_box_width())) {
// If whitespace caused us to break, we swallow the whitespace instead of
// putting it on the next line.
// If we're in a whitespace-collapsing context, we can simply check the flag.
if (item.is_collapsible_whitespace)
break;
// In whitespace-preserving contexts (white-space: pre*), we have to check manually.
auto view = text_node.text_for_rendering().substring_view(item.offset_in_node, item.length_in_node);
if (view.is_whitespace())
break;
}
line_builder.append_text_chunk(
text_node,