mirror of
https://github.com/SerenityOS/serenity
synced 2026-05-14 02:46:22 +02:00
The "isCollapsed" attribute on a selection must "return true if and only if the anchor and focus are the same". In addition to checking that the anchor and focus belonged to the same DOM node, we now also check that they refer to the same position within the node. With this change Ladybird passes all the subtests in the "isCollapsed" WPT suite. https://wpt.live/selection/isCollapsed.html (cherry picked from commit fadb14d31d0d3127e80121ac695fe839908efaa1)
28 lines
797 B
HTML
28 lines
797 B
HTML
<script src="include.js"></script>
|
|
<p id="a">Simply selectable</p>
|
|
|
|
<script>
|
|
test(() => {
|
|
var selection = window.getSelection();
|
|
var range = document.createRange();
|
|
range.setStart(a.firstChild, 0);
|
|
range.setEnd(a.firstChild, 1);
|
|
selection.addRange(range);
|
|
if (selection.isCollapsed) {
|
|
println(`FAIL: "${selection}" is not collapsed`);
|
|
return;
|
|
}
|
|
selection.collapseToStart();
|
|
if (!selection.isCollapsed) {
|
|
println(`FAIL: "${selection}" is collapsed`);
|
|
return;
|
|
}
|
|
selection.removeAllRanges();
|
|
if (!selection.isCollapsed) {
|
|
println(`FAIL: "${selection}" is collapsed`);
|
|
return;
|
|
}
|
|
println("PASS");
|
|
})
|
|
</script>
|