Files
serenity/Tests/LibWeb/Text/input/selection-extend-backwards.html
John Diamond 754c287b45 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.

(cherry picked from commit 18ade57ae96da05c845582ab03b588c55c1e6633)
2024-11-25 08:50:54 -05:00

22 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>