diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 7d719a8baa1..e25b32c49e2 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -1304,6 +1304,10 @@ void Document::update_layout(UpdateLayoutReason reason) if (m_created_for_appropriate_template_contents) return; + // Clear text blocks cache so we rebuild them on the next find action. + if (m_layout_root) + m_layout_root->invalidate_text_blocks_cache(); + invalidate_display_list(); auto* document_element = this->document_element(); diff --git a/Libraries/LibWeb/Layout/Viewport.h b/Libraries/LibWeb/Layout/Viewport.h index f947d4fca53..f6b6d32e0eb 100644 --- a/Libraries/LibWeb/Layout/Viewport.h +++ b/Libraries/LibWeb/Layout/Viewport.h @@ -28,6 +28,7 @@ public: Vector positions; }; Vector const& text_blocks(); + void invalidate_text_blocks_cache() { m_text_blocks.clear(); } const DOM::Document& dom_node() const { return static_cast(*Node::dom_node()); } diff --git a/Tests/LibWeb/Text/expected/HTML/Window-find-mutations.txt b/Tests/LibWeb/Text/expected/HTML/Window-find-mutations.txt new file mode 100644 index 00000000000..2fbc7d4daf6 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/Window-find-mutations.txt @@ -0,0 +1,3 @@ +Selection: [object Text] 0 - [object Text] 6 +Selection: [object Text] 0 - [object Text] 3 +Expected exception: IndexSizeError: Selection.getRangeAt() on empty Selection or with invalid argument diff --git a/Tests/LibWeb/Text/input/HTML/Window-find-mutations.html b/Tests/LibWeb/Text/input/HTML/Window-find-mutations.html new file mode 100644 index 00000000000..1046e6986c5 --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/Window-find-mutations.html @@ -0,0 +1,30 @@ + + +
foobar
+