diff --git a/Libraries/LibWeb/Layout/Viewport.cpp b/Libraries/LibWeb/Layout/Viewport.cpp index 6d5404e6a5f..29d45cb020e 100644 --- a/Libraries/LibWeb/Layout/Viewport.cpp +++ b/Libraries/LibWeb/Layout/Viewport.cpp @@ -68,18 +68,21 @@ void Viewport::update_text_blocks() return TraversalDecision::Continue; } - if (layout_node.is_text_node()) { - auto const& text_node = as(layout_node); - auto& dom_node = const_cast(text_node.dom_node()); - if (text_positions.is_empty()) { - text_positions.empend(dom_node); - } else { - text_positions.empend(dom_node, current_start_position); - } + if (auto* text_node = as_if(layout_node)) { + // https://html.spec.whatwg.org/multipage/interaction.html#inert-subtrees + // When a node is inert: + // - The user agent should ignore the node for the purposes of find-in-page. + if (auto& dom_node = const_cast(text_node->dom_node()); !dom_node.is_inert()) { + if (text_positions.is_empty()) { + text_positions.empend(dom_node); + } else { + text_positions.empend(dom_node, current_start_position); + } - auto const& current_node_text = text_node.text_for_rendering(); - current_start_position += current_node_text.bytes_as_string_view().length(); - builder.append(move(current_node_text)); + auto const& current_node_text = text_node->text_for_rendering(); + current_start_position += current_node_text.bytes_as_string_view().length(); + builder.append(move(current_node_text)); + } } return TraversalDecision::Continue; diff --git a/Tests/LibWeb/Text/expected/HTML/Window-find-inert.txt b/Tests/LibWeb/Text/expected/HTML/Window-find-inert.txt new file mode 100644 index 00000000000..54685434d86 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/Window-find-inert.txt @@ -0,0 +1,2 @@ +window.find("inert") initial result: true +window.find("inert") second call: false diff --git a/Tests/LibWeb/Text/input/HTML/Window-find-inert.html b/Tests/LibWeb/Text/input/HTML/Window-find-inert.html new file mode 100644 index 00000000000..c22a50db991 --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/Window-find-inert.html @@ -0,0 +1,12 @@ + + +
not inert
+
inert
+