forked from LadybirdBrowser/ladybird
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
6 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
window.find(): false | ||
window.find(this): true, selection from: 0 to 4 | ||
window.find(this): false | ||
window.find(A): true, selection from: 8 to 9 | ||
window.find(t): true, selection from: 10 to 11 | ||
window.find(t): true, selection from: 13 to 14 | ||
window.find(t): false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters