mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-04 16:11:54 +00:00
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.
40 lines
1.3 KiB
HTML
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>
|