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

@dizhang168 commented on this pull request.



> @@ -546,24 +566,18 @@ <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
+            [=this=]'s <a>range</a>'s [=tree/root=], <a>reset the range</a> with
+            <var>newFocus</var> and <var>newFocus</var>.
             </li>
             <li>Otherwise, if <var>oldAnchor</var> is [=boundary point/before=]

I went with the first option and updated the steps for setBaseAndExtent to:
> If anchorNode's root is the same as focusNode's root and anchor is before focus, set the composed selection range with anchor and focus. Otherwise, set the composed selection range with focus and anchor.

This is not grabbing the shadow host and only compares the roots. This also means that for shadow tree cases, the focus is the start and the anchor is the end. That might feel a little unintuitive, but it should be fine because:
* For live ranges, this will get collapsed to end (since we first call setStart, then setEnd).
* For composed selection range, we determinate the anchor/focus based on the direction.

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

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

Received on Friday, 7 March 2025 00:08:01 UTC