mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-16 16:12:53 +00: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
27 lines
797 B
HTML
27 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>
|