ladybird/Tests/LibWeb/Text/input/set-selection-inside-shadow-root.html
Tim Ledbetter 34741d09c6 LibWeb: Update Range::set_base_and_extent() to the latest spec text
This allows it to work with content inside shadow roots.
2024-07-04 14:38:56 +02:00

21 lines
933 B
HTML

<script src="include.js"></script>
<div id="root"></div>
<script>
function printSelectionDetails(selection) {
println(`Selection range count: ${selection.rangeCount}`);
if (selection.rangeCount > 0)
println(`Selection start offset: ${selection.getRangeAt(0).startOffset}, end offset: ${selection.getRangeAt(0).endOffset}`);
}
test(() => {
const rootElement = document.getElementById("root");
const shadowRoot = rootElement.attachShadow({ mode: "open" });
shadowRoot.innerHTML = "This is some text";
const selection = window.getSelection();
selection.setBaseAndExtent(shadowRoot, 0, shadowRoot, 1);
println(`Selection range count: ${selection.rangeCount}`);
println(`Selection start offset: ${selection.getRangeAt(0).startOffset}, end offset: ${selection.getRangeAt(0).endOffset}`);
shadowRoot.innerHTML = "";
});
</script>