mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 05:09:12 +00:00
LibWeb: Exclude inert elements from find in page queries
This commit is contained in:
parent
d410fa8381
commit
2e27ffab6c
Notes:
github-actions[bot]
2025-02-21 12:43:06 +00:00
Author: https://github.com/tcl3
Commit: 2e27ffab6c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3475
Reviewed-by: https://github.com/AtkinsSJ ✅
3 changed files with 28 additions and 11 deletions
|
@ -68,18 +68,21 @@ void Viewport::update_text_blocks()
|
||||||
return TraversalDecision::Continue;
|
return TraversalDecision::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (layout_node.is_text_node()) {
|
if (auto* text_node = as_if<Layout::TextNode>(layout_node)) {
|
||||||
auto const& text_node = as<Layout::TextNode>(layout_node);
|
// https://html.spec.whatwg.org/multipage/interaction.html#inert-subtrees
|
||||||
auto& dom_node = const_cast<DOM::Text&>(text_node.dom_node());
|
// When a node is inert:
|
||||||
if (text_positions.is_empty()) {
|
// - The user agent should ignore the node for the purposes of find-in-page.
|
||||||
text_positions.empend(dom_node);
|
if (auto& dom_node = const_cast<DOM::Text&>(text_node->dom_node()); !dom_node.is_inert()) {
|
||||||
} else {
|
if (text_positions.is_empty()) {
|
||||||
text_positions.empend(dom_node, current_start_position);
|
text_positions.empend(dom_node);
|
||||||
}
|
} else {
|
||||||
|
text_positions.empend(dom_node, current_start_position);
|
||||||
|
}
|
||||||
|
|
||||||
auto const& current_node_text = text_node.text_for_rendering();
|
auto const& current_node_text = text_node->text_for_rendering();
|
||||||
current_start_position += current_node_text.bytes_as_string_view().length();
|
current_start_position += current_node_text.bytes_as_string_view().length();
|
||||||
builder.append(move(current_node_text));
|
builder.append(move(current_node_text));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TraversalDecision::Continue;
|
return TraversalDecision::Continue;
|
||||||
|
|
2
Tests/LibWeb/Text/expected/HTML/Window-find-inert.txt
Normal file
2
Tests/LibWeb/Text/expected/HTML/Window-find-inert.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
window.find("inert") initial result: true
|
||||||
|
window.find("inert") second call: false
|
12
Tests/LibWeb/Text/input/HTML/Window-find-inert.html
Normal file
12
Tests/LibWeb/Text/input/HTML/Window-find-inert.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<div>not inert</div>
|
||||||
|
<div inert>inert</div>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
let initialResult = window.find("inert");
|
||||||
|
let secondCallResult = window.find("inert");
|
||||||
|
println(`window.find("inert") initial result: ${initialResult}`);
|
||||||
|
println(`window.find("inert") second call: ${secondCallResult}`);
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue