Re: [whatwg/dom] Should a Range object be able to update a Selection object (#772)

Letting a Range object update a Selection becomes trickier when crossing shadow trees. Here is an example:

```HTML
<html>
<body>
<div id="light">Start outside shadow DOM</div>
<div id="outerHost">outerHost
 <template shadowrootmode="open">
   <slot></slot>
   <div id="innerHost">innerHost
    <template shadowrootmode="open">
      <slot></slot>
    </template>
   </div>
 </template>
</div>

<script>
selection = getSelection();
outerHost = document.getElementById('outerHost')
outerRoot = outerHost.shadowRoot;
innerHost = outerRoot.getElementById('innerHost');

// Step 1
selection.setBaseAndExtent(light.firstChild, 10, innerHost.firstChild, 5);

// Step 2
range = selection.getRangeAt(0);
range.setEnd(innerHost.firstChild, 6);
</script>

</body>
</html>
```

After step 1,
* Composed range should be at start{light.firstChild, 10} and end{innerHost.firstChild, 5}
* Live range is collapsed because it is across tree scopes, at start{innerHost.firstChild, 5} and end{innerHost.firstChild, 5}

After step 2,
* Live range is changed to start{innerHost.firstChild, 5} and end{innerHost.firstChild, 6}
* Composed range should either:

  * A) be updated to same as live range, start{innerHost.firstChild, 5} and end{innerHost.firstChild, 6}
  * B) only update the setEnd, it should be at start{light.firstChild, 10} and end{innerHost.firstChild, 6}
  * C) does not update composed range. It is still at start{light.firstChild, 10} and end{innerHost.firstChild, 5}

Currently, Blink is following option A and Gecko is following option C. Webkit I believe follows C, although it seems to have a bug with its getRangeAt(0) throwing IndexSizeError.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/772#issuecomment-2491887033
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/772/2491887033@github.com>

Received on Thursday, 21 November 2024 17:46:37 UTC