From f4ed4b28064459b9b11f91fcb510833f53d6135a Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 29 Mar 2022 13:35:21 +0200 Subject: [PATCH] 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". --- .../Libraries/LibWeb/Layout/InlineFormattingContext.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 72d5910362..8a9c4c7c83 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -253,8 +253,17 @@ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode) case InlineLevelIterator::Item::Type::Text: { auto& text_node = verify_cast(*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,