ladybird/Tests/LibWeb/Text/input/selection-extend-backwards.html
John Diamond 18ade57ae9 LibWeb: Use correct boundary point comparison in Selection.extend
Previously Selection.extend() used only the relative node order to decide which
direction to extend the selection. This leads to incorrect behaviour if
both the existing and new boundary points are within the same DOM node
and the selection direction is reversed.

This change fixes all the failing subtests in the WPT extend-* test
suites.
2024-10-13 15:11:49 +02:00

21 lines
642 B
HTML

<script src="include.js"></script>
<p id="a">Uno</p>
<script>
test(() => {
var selection = window.getSelection();
selection.setBaseAndExtent(a.firstChild, 3, a.firstChild, 3);
selection.extend(a.firstChild, 0);
if (selection.anchorNode !== a.firstChild
|| selection.anchorOffset !== 3) {
println('FAIL: anchor has moved');
return;
}
if (selection.focusNode !== a.firstChild
|| selection.focusOffset !== 0) {
println('FAIL: focus is not where we expected');
return;
}
println('PASS');
})
</script>