ladybird/Tests/LibWeb/Text/input/HTML/Window-find.html
Tim Ledbetter c4d5ae28ea LibWeb: Implement a minimal version of Window.find()
This is a non-standard API that other browsers implement, which
highlights matching text in the current window.

This is just a thin wrapper around our find in page functionality, the
main motivation for adding this API is that it allows us to write tests
for our find in page implementation.
2024-06-27 10:09:39 +02:00

40 lines
1.3 KiB
HTML

<script src="../include.js"></script>
<div id="textContainer">
<div style="display: none">This is hidden</div>
<div style="visibility: hidden">This is also hidden</div>
<span>this is a test</span>
</div>
<script>
function windowFindTest(string) {
const result = window.find(string);
const selection = window.getSelection();
if (result && selection && selection.rangeCount === 1) {
const range = selection.getRangeAt(0);
println(`window.find("${string}"): ${result}, selection from: ${range.startOffset} to ${range.endOffset}`);
} else {
println(`window.find("${string}"): ${result}`);
}
}
function testBody() {
println(`window.find(): ${window.find()}`);
windowFindTest("this");
windowFindTest("this");
windowFindTest("A");
windowFindTest("t");
windowFindTest("t");
windowFindTest("t");
document.getElementById("textContainer").remove();
}
test(() => {
// This hides the test output until the test is complete.
const testOutputTextContainer = document.getElementById("out");
try {
testOutputTextContainer.style.display = "none";
testBody();
} finally {
testOutputTextContainer.style.display = "block";
}
});
</script>