diff --git a/Libraries/LibWeb/Layout/TextNode.cpp b/Libraries/LibWeb/Layout/TextNode.cpp index 63c1b3cf5ad68..aace349f0f90a 100644 --- a/Libraries/LibWeb/Layout/TextNode.cpp +++ b/Libraries/LibWeb/Layout/TextNode.cpp @@ -410,9 +410,10 @@ Unicode::Segmenter& TextNode::grapheme_segmenter() const return *m_grapheme_segmenter; } -TextNode::ChunkIterator::ChunkIterator(TextNode const& text_node, bool wrap_lines, bool respect_linebreaks) +TextNode::ChunkIterator::ChunkIterator(TextNode const& text_node, bool wrap_lines, bool respect_linebreaks, bool may_contain_caret) : m_wrap_lines(wrap_lines) , m_respect_linebreaks(respect_linebreaks) + , may_contain_caret(may_contain_caret) , m_utf8_view(text_node.text_for_rendering()) , m_font_cascade_list(text_node.computed_values().font_list()) , m_grapheme_segmenter(text_node.grapheme_segmenter()) @@ -481,6 +482,22 @@ Optional TextNode::ChunkIterator::peek(size_t count) Optional TextNode::ChunkIterator::next_without_peek() { + + if (may_contain_caret && m_utf8_view.is_empty() && m_current_index == m_utf8_view.byte_length()) { + auto const& font = m_font_cascade_list.first(); + m_current_index++; + return Chunk { + .view = {}, + .font = font, + .start = 0, + .length = 0, + .has_breaking_newline = false, + .has_breaking_tab = false, + .is_all_whitespace = false, + .text_type = Gfx::GlyphRun::TextType::Common, + }; + } + if (m_current_index >= m_utf8_view.byte_length()) return {}; diff --git a/Libraries/LibWeb/Layout/TextNode.h b/Libraries/LibWeb/Layout/TextNode.h index c9eec9e57bc1f..21bfb9f5ec454 100644 --- a/Libraries/LibWeb/Layout/TextNode.h +++ b/Libraries/LibWeb/Layout/TextNode.h @@ -40,7 +40,7 @@ class TextNode final : public Node { class ChunkIterator { public: - ChunkIterator(TextNode const&, bool wrap_lines, bool respect_linebreaks); + ChunkIterator(TextNode const&, bool wrap_lines, bool respect_linebreaks, bool may_contain_caret); Optional next(); Optional peek(size_t); @@ -51,6 +51,7 @@ class TextNode final : public Node { bool const m_wrap_lines; bool const m_respect_linebreaks; + bool const may_contain_caret; Utf8View m_utf8_view; Gfx::FontCascadeList const& m_font_cascade_list;