Re: [w3c/selection-api] Change Selection to be associated with a composed live range (PR #345)

@sefeng211 commented on this pull request.



> -            The method must throw {{InvalidStateError}} exception if the
-            [=this=] is <a>empty</a>. Otherwise, it must create a new
-            <a>range</a>, [=Range/set the start=] both its [=range/start=] and
-            [=range/end=] to the [=range/end=] of [=this=]'s <a>range</a>, and
-            then set [=this=]'s <a>range</a> to the newly-created <a>range</a>.
-          </p>
+         <p>
+          The method must follow these steps:
+         </p>
+         <ol>
+          <li>If [=this=] is <a>empty</a>, throw an {{InvalidStateError}}
+          exception and abort these steps.
+          </li>
+          <li>Let <var>bp</var> be the [=Range/end=] of [=this=]'s <a>range</a>.
+          </li>
+          <li><a>Set the composed selection range</a> with <var>bp</var> and

So both `collapseToStart` and `collapseToEnd` use the `composed selection range`, not the `legacy selection range`. I wonder if this is breaking change. 

Consider something like 
```
range.setStart(nodeInTree1, 1);
range.setEnd(nodeInTree2, 1);
```
Now `legacy selection range` should be collapsed to `nodeInTree1`, and `composed selection range` doesn't collapse, so `nodeInTree1` and `nodeInTree2`. 

If we now call `selection.collapseToEnd();`, doesn't this set `legacy selection range` also to `nodeInTree2`, whereas it supposes to be remain at "nodeInTree1" for backward compatible? 


> @@ -546,24 +584,20 @@ <h2>
             <var>newFocus</var> be the <a>boundary point</a> (<var>node</var>,
             <var>offset</var>).
             </li>
-            <li>Let <var>newRange</var> be a new <a>range</a>.
-            </li>
-            <li>If <var>node</var>'s [=tree/root=] is not the same as the
-            [=this=]'s <a>range</a>'s [=tree/root=], [=Range/set the start=]
-            <var>newRange</var>'s [=range/start=] and [=range/end=] to
-            <var>newFocus</var>.
+            <li>If <var>node</var>'s [=tree/root=] is not the same as

Here we are comparing `node`'s root, with the `composed selection range`'s root, and `node`'s root could be a shadow root if it's in a totally different tree, and the spec collapses `composed selection range` here. This doesn't feel right, why do we collapse? 

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/selection-api/pull/345#pullrequestreview-2703642318
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/selection-api/pull/345/review/2703642318@github.com>

Received on Thursday, 20 March 2025 18:56:48 UTC