mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
34741d09c6
This allows it to work with content inside shadow roots.
21 lines
933 B
HTML
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>
|