diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 1fcc42a270..27ca5447aa 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -158,7 +158,6 @@ void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode) { containing_block().line_boxes().clear(); - containing_block().ensure_last_line_box(); InlineLevelIterator iterator(containing_block(), layout_mode); LineBuilder line_builder(*this); diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp index 1b9eed559d..ad13a7b3aa 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp @@ -36,13 +36,13 @@ void LineBuilder::begin_new_line() void LineBuilder::append_box(Box& box) { - m_context.containing_block().line_boxes().last().add_fragment(box, 0, 0, box.width(), box.height()); + m_context.containing_block().ensure_last_line_box().add_fragment(box, 0, 0, box.width(), box.height()); m_max_height_on_current_line = max(m_max_height_on_current_line, box.height()); } void LineBuilder::append_text_chunk(TextNode& text_node, size_t offset_in_node, size_t length_in_node, float width, float height) { - m_context.containing_block().line_boxes().last().add_fragment(text_node, offset_in_node, length_in_node, width, height); + m_context.containing_block().ensure_last_line_box().add_fragment(text_node, offset_in_node, length_in_node, width, height); m_max_height_on_current_line = max(m_max_height_on_current_line, height); } @@ -54,7 +54,9 @@ bool LineBuilder::should_break(LayoutMode layout_mode, float next_item_width, bo return true; if (layout_mode == LayoutMode::OnlyRequiredLineBreaks) return false; - auto current_line_width = m_context.containing_block().line_boxes().last().width(); + auto current_line_width = 0.0f; + if (!m_context.containing_block().line_boxes().is_empty()) + current_line_width = m_context.containing_block().line_boxes().last().width(); return (current_line_width + next_item_width) > m_available_width_for_current_line; }